Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Console/Commands/FeedGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Console\Command;
use Laravel\Prompts\Concerns\Colors;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;

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

protected function feedable(): array
{
if ($feed = $this->argument('class')) {
return [$feed => true];
}

return config('feeds.channels');
}

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

return $this->yellow($message);
}

protected function getArguments(): array
{
return [
['class', InputArgument::OPTIONAL, 'The feed class for generation'],
];
}
}
20 changes: 18 additions & 2 deletions src/Console/Commands/FeedMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ public function handle(): void
{
parent::handle();

if ($this->option('with-item')) {
if ($this->option('item')) {
$this->makeFeedItem(
$this->argument('name'),
(bool) $this->option('force')
);
}

if ($this->option('info')) {
$this->makeFeedInfo(
$this->argument('name'),
(bool) $this->option('force')
);
}
}

protected function makeFeedItem(string $name, bool $force): void
Expand All @@ -36,6 +43,14 @@ protected function makeFeedItem(string $name, bool $force): void
]);
}

protected function makeFeedInfo(string $name, bool $force): void
{
$this->call(FeedInfoMakeCommand::class, [
'name' => $name,
'--force' => $force,
]);
}

protected function getStub(): string
{
return __DIR__ . '/../../../stubs/feed.stub';
Expand All @@ -49,7 +64,8 @@ protected function getDefaultNamespace($rootNamespace): string
protected function getOptions(): array
{
return [
['with-item', 'i', InputOption::VALUE_NONE, 'Create the class with feed item'],
['item', 't', InputOption::VALUE_NONE, 'Create the class with feed item'],
['info', 'i', InputOption::VALUE_NONE, 'Create the class with feed info'],
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the feed already exists'],
];
}
Expand Down
6 changes: 6 additions & 0 deletions stubs/feed.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace DummyNamespace;

use DragonCode\LaravelFeed\Data\ElementData;
use DragonCode\LaravelFeed\Feeds\Feed;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -23,6 +24,11 @@ class DummyClass extends Feed
return new ElementData('users');
}

public function info(): FeedInfo
{
return new FeedInfo;
}

public function filename(): string
{
return 'my-feed.xml';
Expand Down
6 changes: 6 additions & 0 deletions tests/.pest/snapshots/Unit/Console/MakeTest/make_feed.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace App\Feeds;

use DragonCode\LaravelFeed\Data\ElementData;
use DragonCode\LaravelFeed\Feeds\Feed;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -23,6 +24,11 @@ class FooBarFeed extends Feed
return new ElementData('users');
}

public function info(): FeedInfo
{
return new FeedInfo;
}

public function filename(): string
{
return 'my-feed.xml';
Expand Down
41 changes: 41 additions & 0 deletions tests/.pest/snapshots/Unit/Console/MakeTest/make_with_info.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Feeds;

use DragonCode\LaravelFeed\Data\ElementData;
use DragonCode\LaravelFeed\Feeds\Feed;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User;

class QweRtyFeed extends Feed
{
public function builder(): Builder
{
return User::query();
}

public function root(): ElementData
{
return new ElementData('users');
}

public function info(): FeedInfo
{
return new FeedInfo;
}

public function filename(): string
{
return 'my-feed.xml';
}

public function item(Model $model): FeedItem
{
return new Items\QweRtyFeedItem($model);
}
}
17 changes: 17 additions & 0 deletions tests/.pest/snapshots/Unit/Console/MakeTest/make_with_info__2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Feeds\Info;

use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;

class QweRtyFeedInfo extends FeedInfo
{
public function toArray(): array
{
return [
//
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace App\Feeds;

use DragonCode\LaravelFeed\Data\ElementData;
use DragonCode\LaravelFeed\Feeds\Feed;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -23,6 +24,11 @@ class QweRtyFeed extends Feed
return new ElementData('users');
}

public function info(): FeedInfo
{
return new FeedInfo;
}

public function filename(): string
{
return 'my-feed.xml';
Expand Down
7 changes: 7 additions & 0 deletions tests/Helpers/paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ function feedPath(string $name): string

return app_path('Feeds/' . $name . '.php');
}

function resolvePath(string $path): string
{
return windows_os()
? str_replace('/', '\\', $path)
: str_replace('\\', '/', $path);
}
40 changes: 35 additions & 5 deletions tests/Unit/Console/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
artisan(FeedMakeCommand::class, [
'name' => 'FooBar',
'--force' => true,
])->assertSuccessful()->run();
])
->expectsOutputToContain(resolvePath('app/Feeds/FooBarFeed.php] created successfully'))
->doesntExpectOutputToContain(resolvePath('app/Feeds/Items'))
->doesntExpectOutputToContain(resolvePath('app/Feeds/Info'))
->assertSuccessful()
->run();

expect('FooBar')->toMatchFeedSnapshot();
});
Expand All @@ -22,12 +27,37 @@
deleteFeed('Items/QweRty');

artisan(FeedMakeCommand::class, [
'name' => 'QweRty',
'--with-item' => true,
'--force' => true,
])->assertSuccessful()->run();
'name' => 'QweRty',
'--item' => true,
'--force' => true,
])
->expectsOutputToContain(resolvePath('app/Feeds/QweRtyFeed.php] created successfully'))
->expectsOutputToContain(resolvePath('app/Feeds/Items/QweRtyFeedItem.php] created successfully'))
->doesntExpectOutputToContain(resolvePath('app/Feeds/Info'))
->assertSuccessful()
->run();

expect('QweRty')
->toMatchFeedSnapshot()
->toMatchFeedItemSnapshot();
});

test('make with info', function () {
deleteFeed('QweRty');
deleteFeed('Items/QweRty');

artisan(FeedMakeCommand::class, [
'name' => 'QweRty',
'--info' => true,
'--force' => true,
])
->expectsOutputToContain(resolvePath('app/Feeds/QweRtyFeed.php] created successfully'))
->doesntExpectOutputToContain(resolvePath('app/Feeds/Items/QweRtyFeedItem.php] created successfully'))
->expectsOutputToContain(resolvePath('app/Feeds/Info/QweRtyFeedInfo'))
->assertSuccessful()
->run();

expect('QweRty')
->toMatchFeedSnapshot()
->toMatchFeedInfoSnapshot();
});