diff --git a/CHANGELOG.md b/CHANGELOG.md index 33e17b0..831cc88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Changes: - Deprecated `Neusta\Pimcore\TestingFramework\Kernel\TestKernel` in favor of `Neusta\Pimcore\TestingFramework\TestKernel` - Deprecated `Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore` in favor of `Neusta\Pimcore\TestingFramework\BootstrapPimcore` +- Deprecated `Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase` in favor of `Neusta\Pimcore\TestingFramework\KernelTestCase` ## v0.12.4 ### Bugfixes: diff --git a/README.md b/README.md index 99c35be..e7e3821 100644 --- a/README.md +++ b/README.md @@ -100,13 +100,13 @@ To enable it again, you can use the `WithAdminMode` trait. The `TestKernel` can be configured dynamically for each test. This is useful if different configurations or dependent bundles are to be tested. -To do this, your test class must inherit from `ConfigurableKernelTestCase`: +To do this, your test class must inherit from `KernelTestCase`: ```php -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\TestKernel; -class SomeTest extends ConfigurableKernelTestCase +class SomeTest extends KernelTestCase { public function test_bundle_with_different_configuration(): void { @@ -130,18 +130,18 @@ class SomeTest extends ConfigurableKernelTestCase #### Attributes -An alternative to passing a `config` closure in the `options` array to `ConfigurableKernelTestCase::bootKernel()` +An alternative to passing a `config` closure in the `options` array to `KernelTestCase::bootKernel()` is to use attributes for the kernel configuration. ```php +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureContainer; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterCompilerPass; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; #[RegisterBundle(SomeBundle::class)] -class SomeTest extends ConfigurableKernelTestCase +class SomeTest extends KernelTestCase { #[ConfigureContainer(__DIR__ . '/Fixtures/some_config.yaml')] #[ConfigureExtension('some_extension', ['config' => 'values'])] @@ -164,10 +164,10 @@ You can also use the `RegisterBundle`, `ConfigureContainer`, `ConfigureExtension to configure the kernel in a data provider. ```php +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; -class SomeTest extends ConfigurableKernelTestCase +class SomeTest extends KernelTestCase { public function provideTestData(): iterable { diff --git a/src/KernelTestCase.php b/src/KernelTestCase.php new file mode 100644 index 0000000..f0ab0d6 --- /dev/null +++ b/src/KernelTestCase.php @@ -0,0 +1,73 @@ + */ + private static iterable $kernelConfigurations = []; + + /** + * @param array{config?: callable(TestKernel):void, environment?: string, debug?: bool, ...} $options + */ + protected static function createKernel(array $options = []): TestKernel + { + $kernel = parent::createKernel($options); + \assert($kernel instanceof TestKernel); + + foreach (self::$kernelConfigurations as $configuration) { + $configuration->configure($kernel); + } + + $kernel->handleOptions($options); + + return $kernel; + } + + /** + * @internal + * + * @before + */ + public function _getKernelConfigurationFromAttributes(): void + { + $class = new \ReflectionClass($this); + $method = $class->getMethod($this->getName(false)); + $providedData = $this->getProvidedData(); + $configurations = []; + + foreach ($class->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + $configurations[] = $attribute->newInstance(); + } + + foreach ($method->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + $configurations[] = $attribute->newInstance(); + } + + if ([] !== $providedData) { + foreach ($providedData as $data) { + if ($data instanceof KernelConfiguration) { + $configurations[] = $data; + } + } + + // remove them from the arguments passed to the test method + (new \ReflectionProperty(TestCase::class, 'data'))->setValue($this, array_values(array_filter( + $providedData, + fn ($data) => !$data instanceof KernelConfiguration, + ))); + } + + self::$kernelConfigurations = $configurations; + } + + protected function tearDown(): void + { + self::$kernelConfigurations = []; + parent::tearDown(); + } +} diff --git a/src/Test/ConfigurableKernelTestCase.php b/src/Test/ConfigurableKernelTestCase.php index 2297818..bfb3428 100644 --- a/src/Test/ConfigurableKernelTestCase.php +++ b/src/Test/ConfigurableKernelTestCase.php @@ -3,73 +3,23 @@ namespace Neusta\Pimcore\TestingFramework\Test; -use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; -use Neusta\Pimcore\TestingFramework\TestKernel; -use PHPUnit\Framework\TestCase; -use Pimcore\Test\KernelTestCase; +use Neusta\Pimcore\TestingFramework\KernelTestCase; -abstract class ConfigurableKernelTestCase extends KernelTestCase -{ - /** @var list */ - private static iterable $kernelConfigurations = []; +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" class is deprecated, use "%s" instead.', + ConfigurableKernelTestCase::class, + KernelTestCase::class, +); - /** - * @param array{config?: callable(TestKernel):void, environment?: string, debug?: bool, ...} $options - */ - protected static function createKernel(array $options = []): TestKernel - { - $kernel = parent::createKernel($options); - \assert($kernel instanceof TestKernel); - - foreach (self::$kernelConfigurations as $configuration) { - $configuration->configure($kernel); - } - - $kernel->handleOptions($options); - - return $kernel; - } +class_alias(KernelTestCase::class, ConfigurableKernelTestCase::class); +if (false) { /** - * @internal - * - * @before + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\KernelTestCase instead */ - public function _getKernelConfigurationFromAttributes(): void - { - $class = new \ReflectionClass($this); - $method = $class->getMethod($this->getName(false)); - $providedData = $this->getProvidedData(); - $configurations = []; - - foreach ($class->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { - $configurations[] = $attribute->newInstance(); - } - - foreach ($method->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { - $configurations[] = $attribute->newInstance(); - } - - if ([] !== $providedData) { - foreach ($providedData as $data) { - if ($data instanceof KernelConfiguration) { - $configurations[] = $data; - } - } - - // remove them from the arguments passed to the test method - (new \ReflectionProperty(TestCase::class, 'data'))->setValue($this, array_values(array_filter( - $providedData, - fn ($data) => !$data instanceof KernelConfiguration, - ))); - } - - self::$kernelConfigurations = $configurations; - } - - protected function tearDown(): void + abstract class ConfigurableKernelTestCase extends KernelTestCase { - self::$kernelConfigurations = []; - parent::tearDown(); } } diff --git a/tests/Functional/CompilerPassTest.php b/tests/Functional/CompilerPassTest.php index db79faf..c009a2e 100644 --- a/tests/Functional/CompilerPassTest.php +++ b/tests/Functional/CompilerPassTest.php @@ -3,14 +3,14 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterCompilerPass; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\DeregisterSomethingPass; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\RegisterSomethingPass; use Symfony\Component\DependencyInjection\Compiler\PassConfig; -final class CompilerPassTest extends ConfigurableKernelTestCase +final class CompilerPassTest extends KernelTestCase { /** * @test diff --git a/tests/Functional/ContainerConfigurationTest.php b/tests/Functional/ContainerConfigurationTest.php index fbdc838..d64435f 100644 --- a/tests/Functional/ContainerConfigurationTest.php +++ b/tests/Functional/ContainerConfigurationTest.php @@ -3,16 +3,16 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureContainer; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; #[RegisterBundle(ConfigurationBundle::class)] -final class ContainerConfigurationTest extends ConfigurableKernelTestCase +final class ContainerConfigurationTest extends KernelTestCase { public function provideDifferentConfigurationFormats(): iterable { diff --git a/tests/Functional/CustomAttributeTest.php b/tests/Functional/CustomAttributeTest.php index 34e41ee..293eca1 100644 --- a/tests/Functional/CustomAttributeTest.php +++ b/tests/Functional/CustomAttributeTest.php @@ -3,10 +3,10 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\Attribute\ConfigureConfigurationBundle; -final class CustomAttributeTest extends ConfigurableKernelTestCase +final class CustomAttributeTest extends KernelTestCase { /** * @test diff --git a/tests/Functional/DataProviderTest.php b/tests/Functional/DataProviderTest.php index c6c3a62..5b0ce29 100644 --- a/tests/Functional/DataProviderTest.php +++ b/tests/Functional/DataProviderTest.php @@ -3,12 +3,12 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; -final class DataProviderTest extends ConfigurableKernelTestCase +final class DataProviderTest extends KernelTestCase { public function provideData(): iterable { diff --git a/tests/Functional/ExtensionConfigurationTest.php b/tests/Functional/ExtensionConfigurationTest.php index 885b53c..24e1a78 100644 --- a/tests/Functional/ExtensionConfigurationTest.php +++ b/tests/Functional/ExtensionConfigurationTest.php @@ -3,13 +3,13 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; -final class ExtensionConfigurationTest extends ConfigurableKernelTestCase +final class ExtensionConfigurationTest extends KernelTestCase { /** * @test diff --git a/tests/Functional/KernelShutdownTest.php b/tests/Functional/KernelShutdownTest.php index 4bc4afd..0d80cbe 100644 --- a/tests/Functional/KernelShutdownTest.php +++ b/tests/Functional/KernelShutdownTest.php @@ -3,11 +3,11 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; +use Neusta\Pimcore\TestingFramework\KernelTestCase; use Neusta\Pimcore\TestingFramework\TestKernel; use Symfony\Component\Filesystem\Filesystem; -class KernelShutdownTest extends ConfigurableKernelTestCase +class KernelShutdownTest extends KernelTestCase { /** * @test