Skip to content

Commit 9db28a9

Browse files
Code duplication is removed
1 parent 3db8bdd commit 9db28a9

File tree

6 files changed

+25
-45
lines changed

6 files changed

+25
-45
lines changed

tests/Feature/EmptyTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
65
use Workbench\App\Feeds\EmptyFeed;
76

8-
use function Pest\Laravel\artisan;
9-
107
test('export', function (bool $pretty) {
118
setPrettyXml($pretty);
129

13-
$feed = app()->make(EmptyFeed::class);
14-
15-
artisan(FeedGenerateCommand::class)->run();
16-
17-
expect($feed->path())->toBeReadableFile();
18-
expect(file_get_contents($feed->path()))->toMatchSnapshot();
10+
expectFeed(EmptyFeed::class);
1911
})->with('boolean');

tests/Feature/FullTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
65
use Workbench\App\Data\NewsFakeData;
76
use Workbench\App\Feeds\FullFeed;
87

9-
use function Pest\Laravel\artisan;
10-
118
test('export', function (bool $pretty) {
129
setPrettyXml($pretty);
1310

1411
createNews(...NewsFakeData::toArray());
1512

16-
$feed = app()->make(FullFeed::class);
17-
18-
artisan(FeedGenerateCommand::class)->run();
19-
20-
expect($feed->path())->toBeReadableFile();
21-
expect(file_get_contents($feed->path()))->toMatchSnapshot();
13+
expectFeed(FullFeed::class);
2214
})->with('boolean');

tests/Feature/PartialTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
65
use Workbench\App\Data\NewsFakeData;
76
use Workbench\App\Feeds\PartialFeed;
87

9-
use function Pest\Laravel\artisan;
10-
118
test('export', function (bool $pretty) {
129
setPrettyXml($pretty);
1310

@@ -17,10 +14,5 @@
1714

1815
createNews(...NewsFakeData::toArray());
1916

20-
$feed = app()->make(PartialFeed::class);
21-
22-
artisan(FeedGenerateCommand::class)->run();
23-
24-
expect($feed->path())->toBeReadableFile();
25-
expect(file_get_contents($feed->path()))->toMatchSnapshot();
17+
expectFeed(PartialFeed::class);
2618
})->with('boolean');

tests/Feature/SitemapTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
65
use Workbench\App\Feeds\SitemapFeed;
76

8-
use function Pest\Laravel\artisan;
9-
107
test('export', function () {
118
createProducts();
129

13-
$feed = app()->make(SitemapFeed::class);
14-
15-
artisan(FeedGenerateCommand::class)->run();
16-
17-
expect($feed->path())->toBeReadableFile();
18-
expect(file_get_contents($feed->path()))->toMatchSnapshot();
10+
expectFeed(SitemapFeed::class);
1911
});

tests/Feature/YandexTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
65
use Workbench\App\Feeds\YandexFeed;
76

8-
use function Pest\Laravel\artisan;
9-
107
test('export', function () {
118
createProducts();
129

13-
$feed = app()->make(YandexFeed::class);
14-
15-
artisan(FeedGenerateCommand::class)->run();
16-
17-
expect($feed->path())->toBeReadableFile();
18-
expect(file_get_contents($feed->path()))->toMatchSnapshot();
10+
expectFeed(YandexFeed::class);
1911
});

tests/Helpers/expects.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use DragonCode\LaravelFeed\Console\Commands\FeedGenerateCommand;
6+
7+
use function Pest\Laravel\artisan;
8+
9+
/**
10+
* @param class-string<DragonCode\LaravelFeed\Feeds\Feed> $feed
11+
*/
12+
function expectFeed(string $feed): void
13+
{
14+
$instance = app($feed);
15+
16+
artisan(FeedGenerateCommand::class)->assertSuccessful()->run();
17+
18+
expect($instance->path())->toBeReadableFile();
19+
expect(file_get_contents($instance->path()))->toMatchSnapshot();
20+
}

0 commit comments

Comments
 (0)