Skip to content

Commit bf62537

Browse files
Merge pull request #33 from TheDragonCode/1.x
Added the generation of the information file to the general command
2 parents 24be123 + c87dfbb commit bf62537

File tree

9 files changed

+148
-7
lines changed

9 files changed

+148
-7
lines changed

src/Console/Commands/FeedGenerateCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Console\Command;
99
use Laravel\Prompts\Concerns\Colors;
1010
use Symfony\Component\Console\Attribute\AsCommand;
11+
use Symfony\Component\Console\Input\InputArgument;
1112

1213
use function app;
1314
use function config;
@@ -28,6 +29,10 @@ public function handle(Generator $generator): void
2829

2930
protected function feedable(): array
3031
{
32+
if ($feed = $this->argument('class')) {
33+
return [$feed => true];
34+
}
35+
3136
return config('feeds.channels');
3237
}
3338

@@ -39,4 +44,11 @@ protected function messageYellow(string $message): string
3944

4045
return $this->yellow($message);
4146
}
47+
48+
protected function getArguments(): array
49+
{
50+
return [
51+
['class', InputArgument::OPTIONAL, 'The feed class for generation'],
52+
];
53+
}
4254
}

src/Console/Commands/FeedMakeCommand.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ public function handle(): void
2020
{
2121
parent::handle();
2222

23-
if ($this->option('with-item')) {
23+
if ($this->option('item')) {
2424
$this->makeFeedItem(
2525
$this->argument('name'),
2626
(bool) $this->option('force')
2727
);
2828
}
29+
30+
if ($this->option('info')) {
31+
$this->makeFeedInfo(
32+
$this->argument('name'),
33+
(bool) $this->option('force')
34+
);
35+
}
2936
}
3037

3138
protected function makeFeedItem(string $name, bool $force): void
@@ -36,6 +43,14 @@ protected function makeFeedItem(string $name, bool $force): void
3643
]);
3744
}
3845

46+
protected function makeFeedInfo(string $name, bool $force): void
47+
{
48+
$this->call(FeedInfoMakeCommand::class, [
49+
'name' => $name,
50+
'--force' => $force,
51+
]);
52+
}
53+
3954
protected function getStub(): string
4055
{
4156
return __DIR__ . '/../../../stubs/feed.stub';
@@ -49,7 +64,8 @@ protected function getDefaultNamespace($rootNamespace): string
4964
protected function getOptions(): array
5065
{
5166
return [
52-
['with-item', 'i', InputOption::VALUE_NONE, 'Create the class with feed item'],
67+
['item', 't', InputOption::VALUE_NONE, 'Create the class with feed item'],
68+
['info', 'i', InputOption::VALUE_NONE, 'Create the class with feed info'],
5369
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the feed already exists'],
5470
];
5571
}

stubs/feed.stub

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace DummyNamespace;
66

77
use DragonCode\LaravelFeed\Data\ElementData;
88
use DragonCode\LaravelFeed\Feeds\Feed;
9+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
910
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
1011
use Illuminate\Database\Eloquent\Builder;
1112
use Illuminate\Database\Eloquent\Model;
@@ -23,6 +24,11 @@ class DummyClass extends Feed
2324
return new ElementData('users');
2425
}
2526

27+
public function info(): FeedInfo
28+
{
29+
return new FeedInfo;
30+
}
31+
2632
public function filename(): string
2733
{
2834
return 'my-feed.xml';

tests/.pest/snapshots/Unit/Console/MakeTest/make_feed.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace App\Feeds;
66

77
use DragonCode\LaravelFeed\Data\ElementData;
88
use DragonCode\LaravelFeed\Feeds\Feed;
9+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
910
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
1011
use Illuminate\Database\Eloquent\Builder;
1112
use Illuminate\Database\Eloquent\Model;
@@ -23,6 +24,11 @@ class FooBarFeed extends Feed
2324
return new ElementData('users');
2425
}
2526

27+
public function info(): FeedInfo
28+
{
29+
return new FeedInfo;
30+
}
31+
2632
public function filename(): string
2733
{
2834
return 'my-feed.xml';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds;
6+
7+
use DragonCode\LaravelFeed\Data\ElementData;
8+
use DragonCode\LaravelFeed\Feeds\Feed;
9+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
10+
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
11+
use Illuminate\Database\Eloquent\Builder;
12+
use Illuminate\Database\Eloquent\Model;
13+
use Illuminate\Foundation\Auth\User;
14+
15+
class QweRtyFeed extends Feed
16+
{
17+
public function builder(): Builder
18+
{
19+
return User::query();
20+
}
21+
22+
public function root(): ElementData
23+
{
24+
return new ElementData('users');
25+
}
26+
27+
public function info(): FeedInfo
28+
{
29+
return new FeedInfo;
30+
}
31+
32+
public function filename(): string
33+
{
34+
return 'my-feed.xml';
35+
}
36+
37+
public function item(Model $model): FeedItem
38+
{
39+
return new Items\QweRtyFeedItem($model);
40+
}
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds\Info;
6+
7+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
8+
9+
class QweRtyFeedInfo extends FeedInfo
10+
{
11+
public function toArray(): array
12+
{
13+
return [
14+
//
15+
];
16+
}
17+
}

tests/.pest/snapshots/Unit/Console/MakeTest/make_with_item.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace App\Feeds;
66

77
use DragonCode\LaravelFeed\Data\ElementData;
88
use DragonCode\LaravelFeed\Feeds\Feed;
9+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
910
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
1011
use Illuminate\Database\Eloquent\Builder;
1112
use Illuminate\Database\Eloquent\Model;
@@ -23,6 +24,11 @@ class QweRtyFeed extends Feed
2324
return new ElementData('users');
2425
}
2526

27+
public function info(): FeedInfo
28+
{
29+
return new FeedInfo;
30+
}
31+
2632
public function filename(): string
2733
{
2834
return 'my-feed.xml';

tests/Helpers/paths.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ function feedPath(string $name): string
1414

1515
return app_path('Feeds/' . $name . '.php');
1616
}
17+
18+
function resolvePath(string $path): string
19+
{
20+
return windows_os()
21+
? str_replace('/', '\\', $path)
22+
: str_replace('\\', '/', $path);
23+
}

tests/Unit/Console/MakeTest.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
artisan(FeedMakeCommand::class, [
1313
'name' => 'FooBar',
1414
'--force' => true,
15-
])->assertSuccessful()->run();
15+
])
16+
->expectsOutputToContain(resolvePath('app/Feeds/FooBarFeed.php] created successfully'))
17+
->doesntExpectOutputToContain(resolvePath('app/Feeds/Items'))
18+
->doesntExpectOutputToContain(resolvePath('app/Feeds/Info'))
19+
->assertSuccessful()
20+
->run();
1621

1722
expect('FooBar')->toMatchFeedSnapshot();
1823
});
@@ -22,12 +27,37 @@
2227
deleteFeed('Items/QweRty');
2328

2429
artisan(FeedMakeCommand::class, [
25-
'name' => 'QweRty',
26-
'--with-item' => true,
27-
'--force' => true,
28-
])->assertSuccessful()->run();
30+
'name' => 'QweRty',
31+
'--item' => true,
32+
'--force' => true,
33+
])
34+
->expectsOutputToContain(resolvePath('app/Feeds/QweRtyFeed.php] created successfully'))
35+
->expectsOutputToContain(resolvePath('app/Feeds/Items/QweRtyFeedItem.php] created successfully'))
36+
->doesntExpectOutputToContain(resolvePath('app/Feeds/Info'))
37+
->assertSuccessful()
38+
->run();
2939

3040
expect('QweRty')
3141
->toMatchFeedSnapshot()
3242
->toMatchFeedItemSnapshot();
3343
});
44+
45+
test('make with info', function () {
46+
deleteFeed('QweRty');
47+
deleteFeed('Items/QweRty');
48+
49+
artisan(FeedMakeCommand::class, [
50+
'name' => 'QweRty',
51+
'--info' => true,
52+
'--force' => true,
53+
])
54+
->expectsOutputToContain(resolvePath('app/Feeds/QweRtyFeed.php] created successfully'))
55+
->doesntExpectOutputToContain(resolvePath('app/Feeds/Items/QweRtyFeedItem.php] created successfully'))
56+
->expectsOutputToContain(resolvePath('app/Feeds/Info/QweRtyFeedInfo'))
57+
->assertSuccessful()
58+
->run();
59+
60+
expect('QweRty')
61+
->toMatchFeedSnapshot()
62+
->toMatchFeedInfoSnapshot();
63+
});

0 commit comments

Comments
 (0)