From a2c507aaff87c9874046a51e6da9c4275bf47108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 6 Mar 2023 13:42:37 +0100 Subject: [PATCH] Test PHPUnit --- composer.json | 3 +- .../SyliusResourceExtension.php | 4 +- .../config/services/integrations/grid.xml | 6 - .../Resources/config/services/state.xml | 6 + src/Bundle/test/config/packages/doctrine.yaml | 5 + .../test/config/packages/framework.yaml | 4 +- .../test/config/packages/messenger.yaml | 11 ++ .../test/config/packages/test/fos_rest.yaml | 1 + .../config/packages/test/sylius_grid.yaml | 6 + .../test_with_attributes/sylius_resource.yaml | 3 + .../sylius_resource.yaml | 0 src/Bundle/test/config/services.yaml | 3 + src/Bundle/test/config/sylius/resources.yaml | 9 ++ .../Command/CreateBoardGameCommand.php | 25 +++ .../Command/CreateBoardGameCommandHandler.php | 36 +++++ .../Command/DeleteBoardGameCommand.php | 25 +++ .../Command/DeleteBoardGameCommandHandler.php | 33 ++++ .../Command/UpdateBoardGameCommand.php | 27 ++++ .../Command/UpdateBoardGameCommandHandler.php | 42 +++++ .../Application/Query/FindBoardGameQuery.php | 25 +++ .../Query/FindBoardGameQueryHandler.php | 30 ++++ .../Exception/MissingBoardGameException.php | 24 +++ .../BoardGameRepositoryInterface.php | 30 ++++ .../Doctrine/DoctrineBoardGameRepository.php | 46 ++++++ .../Sylius/Grid/BoardGameGrid.php | 64 ++++++++ .../Sylius/Resource/BoardGameResource.php | 31 ++++ .../Processor/CreateBoardGameProcessor.php | 51 ++++++ .../Processor/DeleteBoardGameProcessor.php | 40 +++++ .../Processor/UpdateBoardGameProcessor.php | 49 ++++++ .../Provider/BoardGameCollectionProvider.php | 31 ++++ .../Http/Provider/BoardGameItemProvider.php | 45 ++++++ .../Symfony/Form/Type/BoardGameType.php | 36 +++++ src/Bundle/test/src/Kernel.php | 14 ++ .../Command/CommandBusInterface.php | 19 +++ .../Command/CommandHandlerInterface.php | 18 +++ .../Application/Command/CommandInterface.php | 18 +++ .../Application/Query/QueryBusInterface.php | 19 +++ .../Query/QueryHandlerInterface.php | 18 +++ .../Application/Query/QueryInterface.php | 18 +++ .../Domain/Repository/RepositoryInterface.php | 18 +++ .../Symfony/Messenger/MessengerCommandBus.php | 42 +++++ .../Symfony/Messenger/MessengerQueryBus.php | 42 +++++ .../src/Subscription/Entity/Subscription.php | 58 +++++++ .../Subscription/Grid/SubscriptionGrid.php | 63 ++++++++ .../src/Tests/Controller/BoardGameUiTest.php | 145 ++++++++++++++++++ .../Tests/Controller/SubscriptionUiTest.php | 144 +++++++++++++++++ .../Tests/DataFixtures/ORM/board_games.yml | 11 ++ .../DataFixtures/ORM/single_board_game.yml | 7 + .../DataFixtures/ORM/single_subscription.yml | 3 + .../Tests/DataFixtures/ORM/subscriptions.yml | 5 + .../test/templates/board_game/show.html.twig | 4 + .../test/templates/crud/create.html.twig | 7 + .../test/templates/crud/index.html.twig | 35 +++++ .../test/templates/crud/update.html.twig | 8 + .../templates/grid/action/delete.html.twig | 9 ++ .../test/templates/grid/action/show.html.twig | 3 + .../templates/grid/action/update.html.twig | 3 + .../templates/subscription/show.html.twig | 4 + src/Bundle/test/translations/messages.en.yaml | 6 + .../Grid/State/RequestGridProvider.php | 8 +- .../Symfony/Request/State/TwigResponder.php | 2 +- src/Component/spec/Metadata/ResourceSpec.php | 12 +- 62 files changed, 1496 insertions(+), 18 deletions(-) create mode 100644 src/Bundle/test/config/packages/messenger.yaml create mode 100644 src/Bundle/test/config/packages/test/sylius_grid.yaml create mode 100644 src/Bundle/test/config/packages/test_with_attributes/sylius_resource.yaml rename src/Bundle/test/config/routes/{test_with_attributes => }/sylius_resource.yaml (100%) create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/CreateBoardGameCommand.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/CreateBoardGameCommandHandler.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/DeleteBoardGameCommand.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/DeleteBoardGameCommandHandler.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/UpdateBoardGameCommand.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Command/UpdateBoardGameCommandHandler.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Query/FindBoardGameQuery.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Application/Query/FindBoardGameQueryHandler.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Domain/Exception/MissingBoardGameException.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Domain/Repository/BoardGameRepositoryInterface.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Doctrine/DoctrineBoardGameRepository.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Grid/BoardGameGrid.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/CreateBoardGameProcessor.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/DeleteBoardGameProcessor.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/UpdateBoardGameProcessor.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameCollectionProvider.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameItemProvider.php create mode 100644 src/Bundle/test/src/BoardGameBlog/Infrastructure/Symfony/Form/Type/BoardGameType.php create mode 100644 src/Bundle/test/src/Shared/Application/Command/CommandBusInterface.php create mode 100644 src/Bundle/test/src/Shared/Application/Command/CommandHandlerInterface.php create mode 100644 src/Bundle/test/src/Shared/Application/Command/CommandInterface.php create mode 100644 src/Bundle/test/src/Shared/Application/Query/QueryBusInterface.php create mode 100644 src/Bundle/test/src/Shared/Application/Query/QueryHandlerInterface.php create mode 100644 src/Bundle/test/src/Shared/Application/Query/QueryInterface.php create mode 100644 src/Bundle/test/src/Shared/Domain/Repository/RepositoryInterface.php create mode 100644 src/Bundle/test/src/Shared/Infrastructure/Symfony/Messenger/MessengerCommandBus.php create mode 100644 src/Bundle/test/src/Shared/Infrastructure/Symfony/Messenger/MessengerQueryBus.php create mode 100644 src/Bundle/test/src/Subscription/Entity/Subscription.php create mode 100644 src/Bundle/test/src/Subscription/Grid/SubscriptionGrid.php create mode 100644 src/Bundle/test/src/Tests/Controller/BoardGameUiTest.php create mode 100644 src/Bundle/test/src/Tests/Controller/SubscriptionUiTest.php create mode 100644 src/Bundle/test/src/Tests/DataFixtures/ORM/board_games.yml create mode 100644 src/Bundle/test/src/Tests/DataFixtures/ORM/single_board_game.yml create mode 100644 src/Bundle/test/src/Tests/DataFixtures/ORM/single_subscription.yml create mode 100644 src/Bundle/test/src/Tests/DataFixtures/ORM/subscriptions.yml create mode 100644 src/Bundle/test/templates/board_game/show.html.twig create mode 100644 src/Bundle/test/templates/crud/create.html.twig create mode 100644 src/Bundle/test/templates/crud/index.html.twig create mode 100644 src/Bundle/test/templates/crud/update.html.twig create mode 100644 src/Bundle/test/templates/grid/action/delete.html.twig create mode 100644 src/Bundle/test/templates/grid/action/show.html.twig create mode 100644 src/Bundle/test/templates/grid/action/update.html.twig create mode 100644 src/Bundle/test/templates/subscription/show.html.twig create mode 100644 src/Bundle/test/translations/messages.en.yaml diff --git a/composer.json b/composer.json index 23dadf799..d623312f5 100644 --- a/composer.json +++ b/composer.json @@ -75,7 +75,8 @@ "symfony/workflow": "^5.4 || ^6.0", "twig/twig": "^2.12 || ^3.0", "vimeo/psalm": "^4.22", - "rector/rector": "^0.13.5" + "rector/rector": "^0.13.5", + "symfony/messenger": "^5.4 || ^6.0" }, "suggest": { "doctrine/orm": "^2.5", diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index 0f620d4d8..90ddae361 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -155,7 +155,9 @@ private function loadResources(array $loadedResources, ContainerBuilder $contain $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig); - DriverProvider::get($metadata)->load($container, $metadata); + if ($metadata->getDriver()) { + DriverProvider::get($metadata)->load($container, $metadata); + } } } } diff --git a/src/Bundle/Resources/config/services/integrations/grid.xml b/src/Bundle/Resources/config/services/integrations/grid.xml index 73d034651..a593c282e 100644 --- a/src/Bundle/Resources/config/services/integrations/grid.xml +++ b/src/Bundle/Resources/config/services/integrations/grid.xml @@ -65,11 +65,5 @@ - - - - - - diff --git a/src/Bundle/Resources/config/services/state.xml b/src/Bundle/Resources/config/services/state.xml index 7f839e745..144fdce92 100644 --- a/src/Bundle/Resources/config/services/state.xml +++ b/src/Bundle/Resources/config/services/state.xml @@ -50,5 +50,11 @@ + + + + + + diff --git a/src/Bundle/test/config/packages/doctrine.yaml b/src/Bundle/test/config/packages/doctrine.yaml index 61e6b1e69..7103cc5a6 100644 --- a/src/Bundle/test/config/packages/doctrine.yaml +++ b/src/Bundle/test/config/packages/doctrine.yaml @@ -19,3 +19,8 @@ doctrine: type: attribute dir: '%kernel.project_dir%/src/BoardGameBlog/Domain' prefix: 'App\BoardGameBlog\Domain' + Subscription: + is_bundle: false + type: attribute + dir: '%kernel.project_dir%/src/Subscription/Entity' + prefix: 'App\Subscription\Entity' diff --git a/src/Bundle/test/config/packages/framework.yaml b/src/Bundle/test/config/packages/framework.yaml index bb72e46d3..8f95952ae 100644 --- a/src/Bundle/test/config/packages/framework.yaml +++ b/src/Bundle/test/config/packages/framework.yaml @@ -1,6 +1,8 @@ framework: assets: false - translator: { fallbacks: ["%locale%"] } + translator: + default_path: '%kernel.project_dir%/translations' + fallbacks: ["%locale%"] secret: "%secret%" form: ~ csrf_protection: true diff --git a/src/Bundle/test/config/packages/messenger.yaml b/src/Bundle/test/config/packages/messenger.yaml new file mode 100644 index 000000000..3314c6f24 --- /dev/null +++ b/src/Bundle/test/config/packages/messenger.yaml @@ -0,0 +1,11 @@ +framework: + messenger: + default_bus: command.bus + buses: + command.bus: ~ + query.bus: ~ + transports: + sync: 'sync://' + routing: + 'App\Shared\Application\Query\QueryInterface': 'sync' + 'App\Shared\Application\Command\CommandInterface': 'sync' diff --git a/src/Bundle/test/config/packages/test/fos_rest.yaml b/src/Bundle/test/config/packages/test/fos_rest.yaml index dc430ce06..b9c5c4b5b 100644 --- a/src/Bundle/test/config/packages/test/fos_rest.yaml +++ b/src/Bundle/test/config/packages/test/fos_rest.yaml @@ -5,6 +5,7 @@ fos_rest: empty_content: 204 format_listener: rules: + - { path: '^/admin/*', priorities: ['html'], fallback_format: html } - { path: '^/science-books/*', priorities: ['html'], fallback_format: html } - { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: true } exception: diff --git a/src/Bundle/test/config/packages/test/sylius_grid.yaml b/src/Bundle/test/config/packages/test/sylius_grid.yaml new file mode 100644 index 000000000..d6e974cad --- /dev/null +++ b/src/Bundle/test/config/packages/test/sylius_grid.yaml @@ -0,0 +1,6 @@ +sylius_grid: + templates: + action: + delete: 'grid/action/delete.html.twig' + show: 'grid/action/show.html.twig' + update: 'grid/action/update.html.twig' diff --git a/src/Bundle/test/config/packages/test_with_attributes/sylius_resource.yaml b/src/Bundle/test/config/packages/test_with_attributes/sylius_resource.yaml new file mode 100644 index 000000000..c9eec222f --- /dev/null +++ b/src/Bundle/test/config/packages/test_with_attributes/sylius_resource.yaml @@ -0,0 +1,3 @@ +sylius_resource: + mapping: + paths: ['%kernel.project_dir%/src/Entity'] diff --git a/src/Bundle/test/config/routes/test_with_attributes/sylius_resource.yaml b/src/Bundle/test/config/routes/sylius_resource.yaml similarity index 100% rename from src/Bundle/test/config/routes/test_with_attributes/sylius_resource.yaml rename to src/Bundle/test/config/routes/sylius_resource.yaml diff --git a/src/Bundle/test/config/services.yaml b/src/Bundle/test/config/services.yaml index a69c14c63..c4198e4df 100644 --- a/src/Bundle/test/config/services.yaml +++ b/src/Bundle/test/config/services.yaml @@ -86,3 +86,6 @@ services: App\BoardGameBlog\: resource: '../src/BoardGameBlog' + + App\Subscription\: + resource: '../src/Subscription' diff --git a/src/Bundle/test/config/sylius/resources.yaml b/src/Bundle/test/config/sylius/resources.yaml index 4ef2227b5..56d19feef 100644 --- a/src/Bundle/test/config/sylius/resources.yaml +++ b/src/Bundle/test/config/sylius/resources.yaml @@ -1,4 +1,9 @@ sylius_resource: + mapping: + paths: + - '%kernel.project_dir%/src/BoardGameBlog/Infrastructure/Sylius/Resource' + - '%kernel.project_dir%/src/Subscription/Entity' + translation: locale_provider: test.translation_locale_provider @@ -42,3 +47,7 @@ sylius_resource: classes: model: App\Entity\PullRequest form: App\Form\Type\PullRequestType + + app.subscription: + classes: + model: App\Subscription\Entity\Subscription diff --git a/src/Bundle/test/src/BoardGameBlog/Application/Command/CreateBoardGameCommand.php b/src/Bundle/test/src/BoardGameBlog/Application/Command/CreateBoardGameCommand.php new file mode 100644 index 000000000..bae31b489 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Application/Command/CreateBoardGameCommand.php @@ -0,0 +1,25 @@ +name, + ); + + $this->boardGameRepository->save($boardGame); + + return $boardGame; + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Application/Command/DeleteBoardGameCommand.php b/src/Bundle/test/src/BoardGameBlog/Application/Command/DeleteBoardGameCommand.php new file mode 100644 index 000000000..b9e6b20a7 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Application/Command/DeleteBoardGameCommand.php @@ -0,0 +1,25 @@ +boardGameRepository->ofId($command->id)) { + return; + } + + $this->boardGameRepository->remove($boardGame); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Application/Command/UpdateBoardGameCommand.php b/src/Bundle/test/src/BoardGameBlog/Application/Command/UpdateBoardGameCommand.php new file mode 100644 index 000000000..870375cde --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Application/Command/UpdateBoardGameCommand.php @@ -0,0 +1,27 @@ +boardGameRepository->ofId($command->id); + if (null === $boardGame) { + throw new MissingBoardGameException($command->id); + } + + $boardGame->update( + name: $command->name, + ); + + $this->boardGameRepository->save($boardGame); + + return $boardGame; + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Application/Query/FindBoardGameQuery.php b/src/Bundle/test/src/BoardGameBlog/Application/Query/FindBoardGameQuery.php new file mode 100644 index 000000000..9e6cdb46e --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Application/Query/FindBoardGameQuery.php @@ -0,0 +1,25 @@ +repository->ofId($query->id); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Domain/Exception/MissingBoardGameException.php b/src/Bundle/test/src/BoardGameBlog/Domain/Exception/MissingBoardGameException.php new file mode 100644 index 000000000..ddbe3026d --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Domain/Exception/MissingBoardGameException.php @@ -0,0 +1,24 @@ + + */ +interface BoardGameRepositoryInterface extends RepositoryInterface +{ + public function save(BoardGame $boardGame): void; + + public function remove(BoardGame $boardGame): void; + + public function ofId(BoardGameId $id): ?BoardGame; +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Doctrine/DoctrineBoardGameRepository.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Doctrine/DoctrineBoardGameRepository.php new file mode 100644 index 000000000..abfa65751 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Doctrine/DoctrineBoardGameRepository.php @@ -0,0 +1,46 @@ +getEntityManager()->persist($boardGame); + $this->getEntityManager()->flush(); + $this->getEntityManager()->refresh($boardGame); + } + + public function remove(BoardGame $boardGame): void + { + $this->getEntityManager()->remove($boardGame); + $this->getEntityManager()->flush(); + } + + public function ofId(BoardGameId $id): ?BoardGame + { + return $this->find($id->value); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Grid/BoardGameGrid.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Grid/BoardGameGrid.php new file mode 100644 index 000000000..fea119704 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Grid/BoardGameGrid.php @@ -0,0 +1,64 @@ +orderBy('name', 'asc') + ->addField( + StringField::create('name') + ->setPath('name.value') + ->setLabel('Name') + ->setSortable(true, 'name.value'), + ) + ->addActionGroup( + MainActionGroup::create( + CreateAction::create(), + ), + ) + ->addActionGroup( + ItemActionGroup::create( + ShowAction::create(), + UpdateAction::create(), + DeleteAction::create(), + ), + ) + ; + } + + public function getResourceClass(): string + { + return BoardGame::class; + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php index f1bb6fe40..fe7a0f255 100644 --- a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php @@ -14,7 +14,18 @@ namespace App\BoardGameBlog\Infrastructure\Sylius\Resource; use App\BoardGameBlog\Domain\Model\BoardGame; +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Processor\CreateBoardGameProcessor; +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Processor\DeleteBoardGameProcessor; +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Processor\UpdateBoardGameProcessor; +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Provider\BoardGameCollectionProvider; +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Provider\BoardGameItemProvider; +use App\BoardGameBlog\Infrastructure\Symfony\Form\Type\BoardGameType; +use Sylius\Component\Resource\Metadata\Create; +use Sylius\Component\Resource\Metadata\Delete; +use Sylius\Component\Resource\Metadata\Index; use Sylius\Component\Resource\Metadata\Resource; +use Sylius\Component\Resource\Metadata\Show; +use Sylius\Component\Resource\Metadata\Update; use Sylius\Component\Resource\Model\ResourceInterface; use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Validator\Constraints as Assert; @@ -22,9 +33,29 @@ #[Resource( alias: 'app.board_game', section: 'admin', + formType: BoardGameType::class, templatesDir: 'crud', routePrefix: '/admin', )] +#[Create( + processor: CreateBoardGameProcessor::class, +)] +#[Update( + provider: BoardGameItemProvider::class, + processor: UpdateBoardGameProcessor::class, +)] +#[Index( + provider: BoardGameCollectionProvider::class, + grid: 'app_board_game', +)] +#[Show( + template: 'board_game/show.html.twig', + provider: BoardGameItemProvider::class, +)] +#[Delete( + provider: BoardGameItemProvider::class, + processor: DeleteBoardGameProcessor::class, +)] final class BoardGameResource implements ResourceInterface { public function __construct( diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/CreateBoardGameProcessor.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/CreateBoardGameProcessor.php new file mode 100644 index 000000000..c2bb41794 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/CreateBoardGameProcessor.php @@ -0,0 +1,51 @@ +name); + + $command = new CreateBoardGameCommand( + new BoardGameName($data->name), + ); + + /** @var BoardGame $model */ + $model = $this->commandBus->dispatch($command); + + return BoardGameResource::fromModel($model); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/DeleteBoardGameProcessor.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/DeleteBoardGameProcessor.php new file mode 100644 index 000000000..4f6555ac1 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/DeleteBoardGameProcessor.php @@ -0,0 +1,40 @@ +commandBus->dispatch(new DeleteBoardGameCommand(new BoardGameId($data->id))); + + return null; + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/UpdateBoardGameProcessor.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/UpdateBoardGameProcessor.php new file mode 100644 index 000000000..6e98c7294 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Processor/UpdateBoardGameProcessor.php @@ -0,0 +1,49 @@ +id), + null !== $data->name ? new BoardGameName($data->name) : null, + ); + + $model = $this->commandBus->dispatch($command); + + return BoardGameResource::fromModel($model); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameCollectionProvider.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameCollectionProvider.php new file mode 100644 index 000000000..a3b936815 --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameCollectionProvider.php @@ -0,0 +1,31 @@ +requestGridProvider->provide($operation, $context); + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameItemProvider.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameItemProvider.php new file mode 100644 index 000000000..98af8ab9f --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Sylius/State/Http/Provider/BoardGameItemProvider.php @@ -0,0 +1,45 @@ +get(RequestOption::class)?->request(); + Assert::notNull($request); + + $id = (string) $request->attributes->get('id'); + + $model = $this->queryBus->ask(new FindBoardGameQuery(new BoardGameId(Uuid::fromString($id)))); + + return null !== $model ? BoardGameResource::fromModel($model) : null; + } +} diff --git a/src/Bundle/test/src/BoardGameBlog/Infrastructure/Symfony/Form/Type/BoardGameType.php b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Symfony/Form/Type/BoardGameType.php new file mode 100644 index 000000000..654e2318f --- /dev/null +++ b/src/Bundle/test/src/BoardGameBlog/Infrastructure/Symfony/Form/Type/BoardGameType.php @@ -0,0 +1,36 @@ +add('name') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => BoardGameResource::class, + ]); + } +} diff --git a/src/Bundle/test/src/Kernel.php b/src/Bundle/test/src/Kernel.php index b268e2d92..5ea914b18 100644 --- a/src/Bundle/test/src/Kernel.php +++ b/src/Bundle/test/src/Kernel.php @@ -13,10 +13,24 @@ namespace App; +use App\Shared\Application\Command\CommandHandlerInterface; +use App\Shared\Application\Query\QueryHandlerInterface; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; class Kernel extends BaseKernel { use MicroKernelTrait; + + protected function build(ContainerBuilder $container): void + { + $container->registerForAutoconfiguration(QueryHandlerInterface::class) + ->addTag('messenger.message_handler', ['bus' => 'query.bus']) + ; + + $container->registerForAutoconfiguration(CommandHandlerInterface::class) + ->addTag('messenger.message_handler', ['bus' => 'command.bus']) + ; + } } diff --git a/src/Bundle/test/src/Shared/Application/Command/CommandBusInterface.php b/src/Bundle/test/src/Shared/Application/Command/CommandBusInterface.php new file mode 100644 index 000000000..716cad3bf --- /dev/null +++ b/src/Bundle/test/src/Shared/Application/Command/CommandBusInterface.php @@ -0,0 +1,19 @@ +messageBus = $commandBus; + } + + public function dispatch(CommandInterface $command): mixed + { + try { + return $this->handle($command); + } catch (HandlerFailedException $e) { + /** @var array{0: \Throwable} $exceptions */ + $exceptions = $e->getNestedExceptions(); + + throw $exceptions[0]; + } + } +} diff --git a/src/Bundle/test/src/Shared/Infrastructure/Symfony/Messenger/MessengerQueryBus.php b/src/Bundle/test/src/Shared/Infrastructure/Symfony/Messenger/MessengerQueryBus.php new file mode 100644 index 000000000..8413bc147 --- /dev/null +++ b/src/Bundle/test/src/Shared/Infrastructure/Symfony/Messenger/MessengerQueryBus.php @@ -0,0 +1,42 @@ +messageBus = $queryBus; + } + + public function ask(QueryInterface $query): mixed + { + try { + return $this->handle($query); + } catch (HandlerFailedException $e) { + /** @var array{0: \Throwable} $exceptions */ + $exceptions = $e->getNestedExceptions(); + + throw $exceptions[0]; + } + } +} diff --git a/src/Bundle/test/src/Subscription/Entity/Subscription.php b/src/Bundle/test/src/Subscription/Entity/Subscription.php new file mode 100644 index 000000000..d78365d72 --- /dev/null +++ b/src/Bundle/test/src/Subscription/Entity/Subscription.php @@ -0,0 +1,58 @@ +id; + } +} diff --git a/src/Bundle/test/src/Subscription/Grid/SubscriptionGrid.php b/src/Bundle/test/src/Subscription/Grid/SubscriptionGrid.php new file mode 100644 index 000000000..a3e1ea342 --- /dev/null +++ b/src/Bundle/test/src/Subscription/Grid/SubscriptionGrid.php @@ -0,0 +1,63 @@ +orderBy('email', 'asc') + ->addField( + StringField::create('email') + ->setLabel('Email') + ->setSortable(true), + ) + ->addActionGroup( + MainActionGroup::create( + CreateAction::create(), + ), + ) + ->addActionGroup( + ItemActionGroup::create( + ShowAction::create(), + UpdateAction::create(), + DeleteAction::create(), + ), + ) + ; + } + + public function getResourceClass(): string + { + return Subscription::class; + } +} diff --git a/src/Bundle/test/src/Tests/Controller/BoardGameUiTest.php b/src/Bundle/test/src/Tests/Controller/BoardGameUiTest.php new file mode 100644 index 000000000..0263be463 --- /dev/null +++ b/src/Bundle/test/src/Tests/Controller/BoardGameUiTest.php @@ -0,0 +1,145 @@ +loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games/' . $boardGames['ticket_to_ride']->id()); + $response = $this->client->getResponse(); + + $this->assertResponseCode($response, Response::HTTP_OK); + $content = $response->getContent(); + $this->assertStringContainsString(sprintf('ID: %s', $boardGames['ticket_to_ride']->id()), $content); + $this->assertStringContainsString('Name: Ticket to Ride', $content); + } + + /** @test */ + public function it_allows_browsing_board_games(): void + { + $boardGames = $this->loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games'); + $response = $this->client->getResponse(); + + $this->assertResponseCode($response, Response::HTTP_OK); + $content = $response->getContent(); + + $this->assertStringContainsString('Stone Age', $content); + $this->assertStringContainsString(sprintf('Show', $boardGames['stone_age']->id()), $content); + $this->assertStringContainsString(sprintf('Edit', $boardGames['stone_age']->id()), $content); + $this->assertStringContainsString(sprintf('
', $boardGames['stone_age']->id()), $content); + + $this->assertStringContainsString('Ticket to Ride', $content); + $this->assertStringContainsString(sprintf('Show', $boardGames['ticket_to_ride']->id()), $content); + $this->assertStringContainsString(sprintf('Edit', $boardGames['ticket_to_ride']->id()), $content); + $this->assertStringContainsString(sprintf('', $boardGames['ticket_to_ride']->id()), $content); + } + + /** @test */ + public function it_allows_creating_a_board_game(): void + { + $this->loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games/new'); + $this->client->submitForm('Create', [ + 'board_game[name]' => 'Puerto Rico', + ]); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var BoardGame $boardGame */ + $boardGame = static::getContainer()->get(BoardGameRepositoryInterface::class)->findOneBy(['name.value' => 'Puerto Rico']); + + $this->assertNotNull($boardGame); + $this->assertSame('Puerto Rico', (string) $boardGame->name()); + } + + /** @test */ + public function it_does_not_allow_to_create_a_board_game_if_there_is_a_validation_error(): void + { + $this->loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games/new'); + $this->client->submitForm('Create', [ + 'board_game[name]' => null, + ]); + + $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** @test */ + public function it_allows_updating_a_board_game(): void + { + $boardGames = $this->loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games/' . $boardGames['stone_age']->id() . '/edit'); + $this->client->submitForm('Save changes', [ + 'board_game[name]' => 'Puerto Rico', + ]); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var BoardGame $boardGame */ + $boardGame = static::getContainer()->get(BoardGameRepositoryInterface::class)->findOneBy(['name.value' => 'Puerto Rico']); + + $this->assertNotNull($boardGame); + $this->assertSame('Puerto Rico', (string) $boardGame->name()); + } + + /** @test */ + public function it_does_not_allow_to_update_a_board_game_if_there_is_a_validation_error(): void + { + $boardGames = $this->loadFixturesFromFile('board_games.yml'); + + $this->client->request('GET', '/admin/board-games/' . $boardGames['stone_age']->id() . '/edit'); + $this->client->submitForm('Save changes', [ + 'board_game[name]' => null, + ]); + + $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** @test */ + public function it_allows_deleting_a_board_game(): void + { + $this->loadFixturesFromFile('single_board_game.yml'); + + $this->client->request('GET', '/admin/board-games'); + $this->client->submitForm('Delete'); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var BoardGame[] $boardGames */ + $boardGames = static::getContainer()->get(BoardGameRepositoryInterface::class)->findAll(); + + $this->assertEmpty($boardGames); + } + + protected function buildMatcher(): Matcher + { + return $this->matcherFactory->createMatcher(new VoidBacktrace()); + } +} diff --git a/src/Bundle/test/src/Tests/Controller/SubscriptionUiTest.php b/src/Bundle/test/src/Tests/Controller/SubscriptionUiTest.php new file mode 100644 index 000000000..d8d0bcc85 --- /dev/null +++ b/src/Bundle/test/src/Tests/Controller/SubscriptionUiTest.php @@ -0,0 +1,144 @@ +loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $response = $this->client->getResponse(); + + $this->assertResponseCode($response, Response::HTTP_OK); + $content = $response->getContent(); + $this->assertStringContainsString(sprintf('ID: %s', $subscriptions['subscription_marty']->getId()), $content); + $this->assertStringContainsString('Email: marty.mcfly@bttf.com', $content); + } + + /** @test */ + public function it_allows_browsing_subscriptions(): void + { + $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions'); + $response = $this->client->getResponse(); + + $this->assertResponseCode($response, Response::HTTP_OK); + $content = $response->getContent(); + + $this->assertStringContainsString('marty.mcfly@bttf.com', $content); + $this->assertStringContainsString(sprintf('Show', $subscriptions['subscription_marty']->getId()), $content); + $this->assertStringContainsString(sprintf('Edit', $subscriptions['subscription_marty']->getId()), $content); + $this->assertStringContainsString(sprintf('', $subscriptions['subscription_marty']->getId()), $content); + + $this->assertStringContainsString('doc.brown@bttf.com', $content); + $this->assertStringContainsString(sprintf('Show', $subscriptions['subscription_doc']->getId()), $content); + $this->assertStringContainsString(sprintf('Edit', $subscriptions['subscription_doc']->getId()), $content); + $this->assertStringContainsString(sprintf('', $subscriptions['subscription_doc']->getId()), $content); + } + + /** @test */ + public function it_allows_creating_a_subscription(): void + { + $this->loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions/new'); + $this->client->submitForm('Create', [ + 'sylius_resource[email]' => 'biff.tannen@bttf.com', + ]); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var Subscription $subscription */ + $subscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'biff.tannen@bttf.com']); + + $this->assertNotNull($subscription); + $this->assertSame('biff.tannen@bttf.com', (string) $subscription->email); + } + + /** @test */ + public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void + { + $this->loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions/new'); + $this->client->submitForm('Create', [ + 'sylius_resource[email]' => null, + ]); + + $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** @test */ + public function it_allows_updating_a_subscription(): void + { + $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId() . '/edit'); + $this->client->submitForm('Save changes', [ + 'sylius_resource[email]' => 'biff.tannen@bttf.com', + ]); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var Subscription $subscription */ + $subscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'biff.tannen@bttf.com']); + + $this->assertNotNull($subscription); + $this->assertSame('biff.tannen@bttf.com', (string) $subscription->email); + } + + /** @test */ + public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validation_error(): void + { + $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + + $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId() . '/edit'); + $this->client->submitForm('Save changes', [ + 'sylius_resource[email]' => null, + ]); + + $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** @test */ + public function it_allows_deleting_a_subscription(): void + { + $this->loadFixturesFromFile('single_subscription.yml'); + + $this->client->request('GET', '/admin/subscriptions'); + $this->client->submitForm('Delete'); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var Subscription[] $subscriptions */ + $subscriptions = static::getContainer()->get('app.repository.subscription')->findAll(); + + $this->assertEmpty($subscriptions); + } + + protected function buildMatcher(): Matcher + { + return $this->matcherFactory->createMatcher(new VoidBacktrace()); + } +} diff --git a/src/Bundle/test/src/Tests/DataFixtures/ORM/board_games.yml b/src/Bundle/test/src/Tests/DataFixtures/ORM/board_games.yml new file mode 100644 index 000000000..48880014c --- /dev/null +++ b/src/Bundle/test/src/Tests/DataFixtures/ORM/board_games.yml @@ -0,0 +1,11 @@ +App\BoardGameBlog\Domain\ValueObject\BoardGameName: + stone_age_name: + __construct: ['Stone Age'] + ticket_to_ride_name: + __construct: ['Ticket to Ride'] + +App\BoardGameBlog\Domain\Model\BoardGame: + stone_age: + __construct: ['@stone_age_name'] + ticket_to_ride: + __construct: ['@ticket_to_ride_name'] diff --git a/src/Bundle/test/src/Tests/DataFixtures/ORM/single_board_game.yml b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_board_game.yml new file mode 100644 index 000000000..54a976bcb --- /dev/null +++ b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_board_game.yml @@ -0,0 +1,7 @@ +App\BoardGameBlog\Domain\ValueObject\BoardGameName: + ticket_to_ride_name: + __construct: ['Ticket to Ride'] + +App\BoardGameBlog\Domain\Model\BoardGame: + ticket_to_ride: + __construct: ['@ticket_to_ride_name'] diff --git a/src/Bundle/test/src/Tests/DataFixtures/ORM/single_subscription.yml b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_subscription.yml new file mode 100644 index 000000000..9df86d1ab --- /dev/null +++ b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_subscription.yml @@ -0,0 +1,3 @@ +App\Subscription\Entity\Subscription: + subscription_marty: + email: 'marty.mcfly@bttf.com' diff --git a/src/Bundle/test/src/Tests/DataFixtures/ORM/subscriptions.yml b/src/Bundle/test/src/Tests/DataFixtures/ORM/subscriptions.yml new file mode 100644 index 000000000..079cc63e7 --- /dev/null +++ b/src/Bundle/test/src/Tests/DataFixtures/ORM/subscriptions.yml @@ -0,0 +1,5 @@ +App\Subscription\Entity\Subscription: + subscription_marty: + email: 'marty.mcfly@bttf.com' + subscription_doc: + email: 'doc.brown@bttf.com' diff --git a/src/Bundle/test/templates/board_game/show.html.twig b/src/Bundle/test/templates/board_game/show.html.twig new file mode 100644 index 000000000..8e2b5fa83 --- /dev/null +++ b/src/Bundle/test/templates/board_game/show.html.twig @@ -0,0 +1,4 @@ +

Science book

+ +

ID: {{ resource.id }}

+Name: {{ resource.name }} diff --git a/src/Bundle/test/templates/crud/create.html.twig b/src/Bundle/test/templates/crud/create.html.twig new file mode 100644 index 000000000..b772b2ace --- /dev/null +++ b/src/Bundle/test/templates/crud/create.html.twig @@ -0,0 +1,7 @@ +

{{ (operation.resource.applicationName ~ '.ui.new_' ~ operation.resource.name)|trans }}

+ +{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }} +{{ form_widget(form) }} +
+ +{{ form_end(form) }} diff --git a/src/Bundle/test/templates/crud/index.html.twig b/src/Bundle/test/templates/crud/index.html.twig new file mode 100644 index 000000000..ef0a5265c --- /dev/null +++ b/src/Bundle/test/templates/crud/index.html.twig @@ -0,0 +1,35 @@ +

{{ (operation.resource.applicationName ~ '.ui.' ~ operation.resource.pluralName)|trans }}

+ +{% set grid = resources %} +{% set definition = grid.definition %} + + + + + {% for field in definition.fields %} + {% if field.enabled %} + + {% endif %} + {% if definition.actionGroups.item is defined and definition.getEnabledActions('item')|length > 0 %} + + {% endif %} + {% endfor %} + + + + {% for resource in resources.data %} + + {% for field in definition.enabledFields %} + + + {% endfor %} + + {% endfor %} + + +
{{ field.label|trans }}Actions
{{ sylius_grid_render_field(grid, field, resource) }} + {% for action in definition.getEnabledActions('item') %} + {{ sylius_grid_render_action(grid, action, resource) }} + {% endfor %} +
+ diff --git a/src/Bundle/test/templates/crud/update.html.twig b/src/Bundle/test/templates/crud/update.html.twig new file mode 100644 index 000000000..f8a06e568 --- /dev/null +++ b/src/Bundle/test/templates/crud/update.html.twig @@ -0,0 +1,8 @@ +

{{ (operation.resource.applicationName ~ '.ui.edit_' ~ operation.resource.name)|trans }}

+ +{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }} + +{{ form_widget(form) }} +
+ +{{ form_end(form) }} diff --git a/src/Bundle/test/templates/grid/action/delete.html.twig b/src/Bundle/test/templates/grid/action/delete.html.twig new file mode 100644 index 000000000..e40ec82aa --- /dev/null +++ b/src/Bundle/test/templates/grid/action/delete.html.twig @@ -0,0 +1,9 @@ +{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('delete')), options.link.parameters|default({'id': data.id}))) %} + + + + + +
diff --git a/src/Bundle/test/templates/grid/action/show.html.twig b/src/Bundle/test/templates/grid/action/show.html.twig new file mode 100644 index 000000000..b3961e64e --- /dev/null +++ b/src/Bundle/test/templates/grid/action/show.html.twig @@ -0,0 +1,3 @@ +{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('show')), options.link.parameters|default({'id': data.id}))) %} + +Show diff --git a/src/Bundle/test/templates/grid/action/update.html.twig b/src/Bundle/test/templates/grid/action/update.html.twig new file mode 100644 index 000000000..e82376f0c --- /dev/null +++ b/src/Bundle/test/templates/grid/action/update.html.twig @@ -0,0 +1,3 @@ +{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('update')), options.link.parameters|default({'id': data.id}))) %} + +Edit diff --git a/src/Bundle/test/templates/subscription/show.html.twig b/src/Bundle/test/templates/subscription/show.html.twig new file mode 100644 index 000000000..b59b926d4 --- /dev/null +++ b/src/Bundle/test/templates/subscription/show.html.twig @@ -0,0 +1,4 @@ +

Subscription

+ +

ID: {{ resource.id }}

+Email: {{ resource.email }} diff --git a/src/Bundle/test/translations/messages.en.yaml b/src/Bundle/test/translations/messages.en.yaml new file mode 100644 index 000000000..bd5bc47f1 --- /dev/null +++ b/src/Bundle/test/translations/messages.en.yaml @@ -0,0 +1,6 @@ +app: + ui: + board_games: Board games + edit_board_game: Edit board game + new_board_game: New board game + new_subscription: New subscription diff --git a/src/Component/Grid/State/RequestGridProvider.php b/src/Component/Grid/State/RequestGridProvider.php index c0e846dad..1470a2241 100644 --- a/src/Component/Grid/State/RequestGridProvider.php +++ b/src/Component/Grid/State/RequestGridProvider.php @@ -25,13 +25,17 @@ final class RequestGridProvider implements ProviderInterface { public function __construct( - private GridViewFactoryInterface $gridViewFactory, - private GridProviderInterface $gridProvider, + private ?GridViewFactoryInterface $gridViewFactory = null, + private ?GridProviderInterface $gridProvider = null, ) { } public function provide(Operation $operation, Context $context): object|iterable|null { + if (null === $this->gridViewFactory || null === $this->gridProvider) { + throw new \LogicException('You can not use a grid if Sylius Grid Bundle is not available. Try running "composer require sylius/grid-bundle".'); + } + $grid = $operation->getGrid(); if (null === $grid) { diff --git a/src/Component/Symfony/Request/State/TwigResponder.php b/src/Component/Symfony/Request/State/TwigResponder.php index 0fd9f441a..eb998e25b 100644 --- a/src/Component/Symfony/Request/State/TwigResponder.php +++ b/src/Component/Symfony/Request/State/TwigResponder.php @@ -67,6 +67,6 @@ public function respond(mixed $data, Operation $operation, Context $context): ?R $this->contextFactory->create($data, $operation, $context), ); - return new Response($content); + return new Response($content, $isValid ? Response::HTTP_OK : Response::HTTP_UNPROCESSABLE_ENTITY); } } diff --git a/src/Component/spec/Metadata/ResourceSpec.php b/src/Component/spec/Metadata/ResourceSpec.php index 2eb1cdf6a..e61e5276c 100644 --- a/src/Component/spec/Metadata/ResourceSpec.php +++ b/src/Component/spec/Metadata/ResourceSpec.php @@ -140,18 +140,18 @@ function it_can_be_constructed_with_a_templates_dir(): void $this->getTemplatesDir()->shouldReturn('book'); } - function it_can_be_constructed_with_a_plural_name(): void + function it_can_be_constructed_with_a_route_prefix(): void { - $this->beConstructedWith('app.book', null, null, null, null, null, 'books'); + $this->beConstructedWith('app.book', null, null, null, '/admin'); - $this->getPluralName()->shouldReturn('books'); + $this->getRoutePrefix()->shouldReturn('/admin'); } - function it_can_be_constructed_with_a_route_prefix(): void + function it_can_be_constructed_with_a_plural_name(): void { - $this->beConstructedWith('app.book', null, null, null, '/admin'); + $this->beConstructedWith('app.book', null, null, null, null, null, 'books'); - $this->getRoutePrefix()->shouldReturn('/admin'); + $this->getPluralName()->shouldReturn('books'); } function it_can_be_constructed_with_operations(): void