From 06a8cf091c68fc3fd63cfa835193bb8ec5cf55db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 15 May 2024 15:42:56 +0200 Subject: [PATCH] Add tests for compiler passes --- .../Compiler/FosRestPassTest.php | 51 +++++++++++++++++++ .../Compiler/HateoasPassTest.php | 51 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php create mode 100644 tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php diff --git a/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php b/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php new file mode 100644 index 000000000..ebecaed4e --- /dev/null +++ b/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php @@ -0,0 +1,51 @@ +setParameter('kernel.bundles', []); + + $this->compile(); + + $this->assertContainerBuilderNotHasService('sylius.resource_controller.view_handler'); + } + + /** @test */ + public function it_keeps_the_view_handler_if_fos_rest_is_available(): void + { + $this->setParameter('kernel.bundles', [FOSRestBundle::class]); + + $this->compile(); + + $this->assertContainerBuilderHasService('sylius.resource_controller.view_handler'); + } + + protected function registerCompilerPass(ContainerBuilder $container): void + { + $this->registerService('sylius.resource_controller.view_handler', ViewHandler::class); + $this->setParameter('kernel.bundles', []); + + $container->addCompilerPass(new FosRestPass()); + } +} diff --git a/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php b/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php new file mode 100644 index 000000000..73397541c --- /dev/null +++ b/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php @@ -0,0 +1,51 @@ +setParameter('kernel.bundles', []); + + $this->compile(); + + $this->assertContainerBuilderNotHasService('sylius.resource_controller.pagerfanta_representation_factory'); + } + + /** @test */ + public function it_keeps_the_view_handler_if_fos_rest_is_available(): void + { + $this->setParameter('kernel.bundles', [BazingaHateoasBundle::class]); + + $this->compile(); + + $this->assertContainerBuilderHasService('sylius.resource_controller.pagerfanta_representation_factory'); + } + + protected function registerCompilerPass(ContainerBuilder $container): void + { + $this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class); + $this->setParameter('kernel.bundles', []); + + $container->addCompilerPass(new HateoasPass()); + } +}