|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Neusta\Pimcore\TestingFramework\Tests\Functional; |
| 5 | + |
| 6 | +use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; |
| 7 | +use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureRoute; |
| 8 | +use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; |
| 9 | +use Neusta\Pimcore\TestingFramework\Tests\Fixtures\Controller\ExampleController; |
| 10 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 11 | +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
| 12 | +use Symfony\Component\Routing\Route; |
| 13 | + |
| 14 | +final class RouteConfigurationTest extends ConfigurableKernelTestCase |
| 15 | +{ |
| 16 | + public function provideDifferentConfigurationFormats(): iterable |
| 17 | + { |
| 18 | + yield 'YAML' => [__DIR__ . '/../Fixtures/Resources/Routes/routes.yaml']; |
| 19 | + yield 'XML' => [__DIR__ . '/../Fixtures/Resources/Routes/routes.xml']; |
| 20 | + yield 'PHP' => [__DIR__ . '/../Fixtures/Resources/Routes/routes.php']; |
| 21 | + yield 'Callable' => [function (RoutingConfigurator $routes): void { |
| 22 | + $routes->add('example_route', '/example')->controller(ExampleController::class); |
| 23 | + }]; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @test |
| 28 | + * |
| 29 | + * @dataProvider provideDifferentConfigurationFormats |
| 30 | + */ |
| 31 | + public function different_configuration_formats(string|callable $config): void |
| 32 | + { |
| 33 | + self::bootKernel(['config' => fn (TestKernel $kernel) => $kernel->addTestRoute($config)]); |
| 34 | + |
| 35 | + self::assertRouteConfiguration(self::getContainer()); |
| 36 | + } |
| 37 | + |
| 38 | + public function provideDifferentConfigurationFormatsViaKernelConfigurationObject(): iterable |
| 39 | + { |
| 40 | + yield 'YAML' => [new ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.yaml')]; |
| 41 | + yield 'XML' => [new ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.xml')]; |
| 42 | + yield 'PHP' => [new ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.php')]; |
| 43 | + yield 'Callable' => [new ConfigureRoute(function (RoutingConfigurator $routes): void { |
| 44 | + $routes->add('example_route', '/example')->controller(ExampleController::class); |
| 45 | + })]; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @test |
| 50 | + * |
| 51 | + * @dataProvider provideDifferentConfigurationFormatsViaKernelConfigurationObject |
| 52 | + */ |
| 53 | + public function different_configuration_formats_via_data_provider(): void |
| 54 | + { |
| 55 | + self::assertRouteConfiguration(self::getContainer()); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @test |
| 60 | + */ |
| 61 | + #[ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.yaml')] |
| 62 | + public function configuration_in_yaml_via_attribute(): void |
| 63 | + { |
| 64 | + self::assertRouteConfiguration(self::getContainer()); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @test |
| 69 | + */ |
| 70 | + #[ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.xml')] |
| 71 | + public function configuration_in_xml_via_attribute(): void |
| 72 | + { |
| 73 | + self::assertRouteConfiguration(self::getContainer()); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @test |
| 78 | + */ |
| 79 | + #[ConfigureRoute(__DIR__ . '/../Fixtures/Resources/Routes/routes.php')] |
| 80 | + public function configuration_in_php_via_attribute(): void |
| 81 | + { |
| 82 | + self::assertRouteConfiguration(self::getContainer()); |
| 83 | + } |
| 84 | + |
| 85 | + public static function assertRouteConfiguration(ContainerInterface $container): void |
| 86 | + { |
| 87 | + $route = $container->get('router')->getRouteCollection()->get('example_route'); |
| 88 | + |
| 89 | + self::assertInstanceOf(Route::class, $route); |
| 90 | + self::assertSame('/example', $route->getPath()); |
| 91 | + } |
| 92 | +} |
0 commit comments