diff --git a/tests/Feature/EmptyTest.php b/tests/Feature/EmptyTest.php index 686851d..8d5e406 100644 --- a/tests/Feature/EmptyTest.php +++ b/tests/Feature/EmptyTest.php @@ -2,18 +2,10 @@ declare(strict_types=1); -use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand; use Workbench\App\Feeds\EmptyFeed; -use function Pest\Laravel\artisan; - test('export', function (bool $pretty) { setPrettyXml($pretty); - $feed = app()->make(EmptyFeed::class); - - artisan(FeedGenerateCommand::class)->run(); - - expect($feed->path())->toBeReadableFile(); - expect(file_get_contents($feed->path()))->toMatchSnapshot(); + expectFeed(EmptyFeed::class); })->with('boolean'); diff --git a/tests/Feature/FullTest.php b/tests/Feature/FullTest.php index daad8b4..d3df498 100644 --- a/tests/Feature/FullTest.php +++ b/tests/Feature/FullTest.php @@ -2,21 +2,13 @@ declare(strict_types=1); -use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand; use Workbench\App\Data\NewsFakeData; use Workbench\App\Feeds\FullFeed; -use function Pest\Laravel\artisan; - test('export', function (bool $pretty) { setPrettyXml($pretty); createNews(...NewsFakeData::toArray()); - $feed = app()->make(FullFeed::class); - - artisan(FeedGenerateCommand::class)->run(); - - expect($feed->path())->toBeReadableFile(); - expect(file_get_contents($feed->path()))->toMatchSnapshot(); + expectFeed(FullFeed::class); })->with('boolean'); diff --git a/tests/Feature/PartialTest.php b/tests/Feature/PartialTest.php index ae2d9cf..27a2b6e 100644 --- a/tests/Feature/PartialTest.php +++ b/tests/Feature/PartialTest.php @@ -2,12 +2,9 @@ declare(strict_types=1); -use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand; use Workbench\App\Data\NewsFakeData; use Workbench\App\Feeds\PartialFeed; -use function Pest\Laravel\artisan; - test('export', function (bool $pretty) { setPrettyXml($pretty); @@ -17,10 +14,5 @@ createNews(...NewsFakeData::toArray()); - $feed = app()->make(PartialFeed::class); - - artisan(FeedGenerateCommand::class)->run(); - - expect($feed->path())->toBeReadableFile(); - expect(file_get_contents($feed->path()))->toMatchSnapshot(); + expectFeed(PartialFeed::class); })->with('boolean'); diff --git a/tests/Feature/SitemapTest.php b/tests/Feature/SitemapTest.php index 0547e85..6cc3914 100644 --- a/tests/Feature/SitemapTest.php +++ b/tests/Feature/SitemapTest.php @@ -2,18 +2,10 @@ declare(strict_types=1); -use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand; use Workbench\App\Feeds\SitemapFeed; -use function Pest\Laravel\artisan; - test('export', function () { createProducts(); - $feed = app()->make(SitemapFeed::class); - - artisan(FeedGenerateCommand::class)->run(); - - expect($feed->path())->toBeReadableFile(); - expect(file_get_contents($feed->path()))->toMatchSnapshot(); + expectFeed(SitemapFeed::class); }); diff --git a/tests/Feature/YandexTest.php b/tests/Feature/YandexTest.php index 3e8461f..e7b77f9 100644 --- a/tests/Feature/YandexTest.php +++ b/tests/Feature/YandexTest.php @@ -2,18 +2,10 @@ declare(strict_types=1); -use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand; use Workbench\App\Feeds\YandexFeed; -use function Pest\Laravel\artisan; - test('export', function () { createProducts(); - $feed = app()->make(YandexFeed::class); - - artisan(FeedGenerateCommand::class)->run(); - - expect($feed->path())->toBeReadableFile(); - expect(file_get_contents($feed->path()))->toMatchSnapshot(); + expectFeed(YandexFeed::class); }); diff --git a/tests/Helpers/expects.php b/tests/Helpers/expects.php new file mode 100644 index 0000000..fe5c6a4 --- /dev/null +++ b/tests/Helpers/expects.php @@ -0,0 +1,20 @@ + $feed + */ +function expectFeed(string $feed): void +{ + $instance = app($feed); + + artisan(FeedGenerateCommand::class)->assertSuccessful()->run(); + + expect($instance->path())->toBeReadableFile(); + expect(file_get_contents($instance->path()))->toMatchSnapshot(); +}