From 6ccf82c1b977641e2d79120aef1dae4d28dd6bed Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Mon, 11 Mar 2024 15:30:51 +0100 Subject: [PATCH] Test bundle & config --- .github/workflows/tests.yaml | 4 ++ composer.json | 4 +- .../ConfigurationBundle.php | 10 ++++ .../DependencyInjection/Configuration.php | 26 +++++++++ .../ConfigurationExtension.php | 16 ++++++ .../Resources/ConfigurationBundle/config.php | 12 ++++ .../Resources/ConfigurationBundle/config.xml | 14 +++++ .../Resources/ConfigurationBundle/config.yaml | 8 +++ tests/Functional/BundleConfigurationTest.php | 57 +++++++++++++++++++ tests/app/config/.gitkeep | 0 tests/bootstrap.php | 11 +++- 11 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php create mode 100644 tests/Fixtures/ConfigurationBundle/DependencyInjection/Configuration.php create mode 100644 tests/Fixtures/ConfigurationBundle/DependencyInjection/ConfigurationExtension.php create mode 100644 tests/Fixtures/Resources/ConfigurationBundle/config.php create mode 100644 tests/Fixtures/Resources/ConfigurationBundle/config.xml create mode 100644 tests/Fixtures/Resources/ConfigurationBundle/config.yaml create mode 100644 tests/Functional/BundleConfigurationTest.php create mode 100644 tests/app/config/.gitkeep diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9dd02e1..0742ac3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -39,5 +39,9 @@ jobs: with: dependency-versions: ${{ matrix.dependencies }} + - name: Add Pimcore Admin UI + run: composer require --dev pimcore/admin-ui-classic-bundle --no-interaction + if: matrix.dependencies == 'highest' + - name: Execute tests run: composer tests diff --git a/composer.json b/composer.json index 528df32..ac8d9b7 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,9 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Unit\\Neusta\\Pimcore\\TestingFramework\\": "tests/Unit" + "Fixtures\\": "tests/Fixtures/", + "Tests\\Functional\\Neusta\\Pimcore\\TestingFramework\\": "tests/Functional/", + "Tests\\Unit\\Neusta\\Pimcore\\TestingFramework\\": "tests/Unit/" } }, "config": { diff --git a/tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php b/tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php new file mode 100644 index 0000000..3791602 --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php @@ -0,0 +1,10 @@ +getRootNode() + ->children() + ->scalarNode('foo')->isRequired()->end() + ->arrayNode('bar') + ->isRequired() + ->scalarPrototype() + ->end() + ->end(); + + return $tree; + } +} diff --git a/tests/Fixtures/ConfigurationBundle/DependencyInjection/ConfigurationExtension.php b/tests/Fixtures/ConfigurationBundle/DependencyInjection/ConfigurationExtension.php new file mode 100644 index 0000000..8beb888 --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/DependencyInjection/ConfigurationExtension.php @@ -0,0 +1,16 @@ +setParameter('configuration.foo', $mergedConfig['foo']); + $container->setParameter('configuration.bar', $mergedConfig['bar']); + } +} diff --git a/tests/Fixtures/Resources/ConfigurationBundle/config.php b/tests/Fixtures/Resources/ConfigurationBundle/config.php new file mode 100644 index 0000000..7e08608 --- /dev/null +++ b/tests/Fixtures/Resources/ConfigurationBundle/config.php @@ -0,0 +1,12 @@ +extension('configuration', [ + 'foo' => 'value1', + 'bar' => ['value2', 'value3'], + ]); + + $container->services()->set('something', stdClass::class)->public(); +}; diff --git a/tests/Fixtures/Resources/ConfigurationBundle/config.xml b/tests/Fixtures/Resources/ConfigurationBundle/config.xml new file mode 100644 index 0000000..a5c821d --- /dev/null +++ b/tests/Fixtures/Resources/ConfigurationBundle/config.xml @@ -0,0 +1,14 @@ + + + + value2 + value3 + + + + + + diff --git a/tests/Fixtures/Resources/ConfigurationBundle/config.yaml b/tests/Fixtures/Resources/ConfigurationBundle/config.yaml new file mode 100644 index 0000000..3b12683 --- /dev/null +++ b/tests/Fixtures/Resources/ConfigurationBundle/config.yaml @@ -0,0 +1,8 @@ +configuration: + foo: value1 + bar: [value2, value3] + +services: + something: + class: \stdClass + public: true diff --git a/tests/Functional/BundleConfigurationTest.php b/tests/Functional/BundleConfigurationTest.php new file mode 100644 index 0000000..8a83bc4 --- /dev/null +++ b/tests/Functional/BundleConfigurationTest.php @@ -0,0 +1,57 @@ + function (TestKernel $kernel) { + $kernel->addTestBundle(ConfigurationBundle::class); + $kernel->addTestExtensionConfig('configuration', [ + 'foo' => 'value1', + 'bar' => ['value2', 'value3'], + ]); + }]); + + $container = self::getContainer(); + + $this->assertEquals('value1', $container->getParameter('configuration.foo')); + $this->assertEquals(['value2', 'value3'], $container->getParameter('configuration.bar')); + } + + public function provideDifferentConfigurationFormats(): iterable + { + yield 'YAML' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.yaml']; + yield 'XML' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.xml']; + yield 'PHP' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.php']; + } + + /** + * @test + * + * @dataProvider provideDifferentConfigurationFormats + */ + public function different_configuration_formats(string $config): void + { + self::bootKernel(['config' => function (TestKernel $kernel) use ($config) { + $kernel->addTestBundle(ConfigurationBundle::class); + $kernel->addTestConfig($config); + }]); + + $container = self::getContainer(); + + $this->assertEquals('value1', $container->getParameter('configuration.foo')); + $this->assertEquals(['value2', 'value3'], $container->getParameter('configuration.bar')); + self::assertInstanceOf(\stdClass::class, $container->get('something', ContainerInterface::NULL_ON_INVALID_REFERENCE)); + } +} diff --git a/tests/app/config/.gitkeep b/tests/app/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 46902d0..bb90dfe 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,8 +2,15 @@ declare(strict_types=1); +use Doctrine\Common\Annotations\AnnotationRegistry; +use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore; + include dirname(__DIR__) . '/vendor/autoload.php'; -Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); +AnnotationRegistry::registerLoader('class_exists'); -Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore::bootstrap(); +BootstrapPimcore::bootstrap( + PIMCORE_PROJECT_ROOT: __DIR__ . '/app', + KERNEL_CLASS: TestKernel::class, +);