Skip to content

Commit

Permalink
refactor(feed): update FeedCommand.php and FeedCommandTest.php
Browse files Browse the repository at this point in the history
- Updated FeedCommand.php to set the modified date
- Added Process facade to FeedCommand.php for running git diff command
- Updated the test cases in FeedCommandTest.php to throw specific exceptions
  • Loading branch information
guanguans committed Apr 12, 2024
1 parent e623b6d commit 5ac68df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions app/Commands/FeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Laminas\Feed\Writer\Feed;

/**
Expand Down Expand Up @@ -84,16 +85,20 @@ static function (Collection $carry, string $line) use (&$date): Collection {
$feed->addEntry($entry);
});

$feed->count()
? $feed->setDateModified($feed->getEntry()->getDateModified())
: $feed->setDateModified(new \DateTimeImmutable);
$feed->setDateModified($feed->getEntry()->getDateModified());

foreach (['atom', 'rss'] as $type) {
$name = "README.$type";
$feed->setFeedLink("https://raw.githubusercontent.com/guanguans/favorite-link/master/$name", $type);
File::put(base_path($name), $feed->export($type));
}
})
->tap(fn () => Process::run(
'git diff --color README.*',
function (string $type, string $line): void {
$this->output->write($line);
}
))
->tap(fn () => $this->output->success('Feed is done!'));
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/FeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

use App\Commands\FeedCommand;

it('will throw an InvalidArgumentException', function (): void {
it('will throw an InvalidArgumentException of Symfony', function (): void {
$this->artisan(FeedCommand::class, ['--from' => $this->faker()->filePath()]);
})->group(__DIR__, __FILE__)->throws(\Symfony\Component\Console\Exception\InvalidArgumentException::class);

it('can generate empty feed', function (): void {
it('will throw an InvalidArgumentException of Laminas', function (): void {
$this->artisan(FeedCommand::class, ['--from' => fixtures_path('README.md')])->assertOk();
})->group(__DIR__, __FILE__);
})->group(__DIR__, __FILE__)->throws(\Laminas\Feed\Writer\Exception\InvalidArgumentException::class);

it('can generate feed', function (): void {
$this->artisan(FeedCommand::class)->assertOk();
})->group(__DIR__, __FILE__)->depends('it can generate empty feed');
})->group(__DIR__, __FILE__);

0 comments on commit 5ac68df

Please sign in to comment.