diff --git a/CHANGELOG.md b/CHANGELOG.md index 831cc88..809889f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,16 @@ ## v0.13.0 ### 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` +- 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` +- Deprecated `Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration` + in favor of `\Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel` +- Deprecated `Neusta\Pimcore\TestingFramework\Test\Attribute\{ConfigureContainer,ConfigureExtension,RegisterBundle,RegisterCompilerPass}` + in favor of `\Neusta\Pimcore\TestingFramework\Attribute\Kernel\{ConfigureContainer,ConfigureExtension,RegisterBundle,RegisterCompilerPass}` ## v0.12.4 ### Bugfixes: diff --git a/README.md b/README.md index e7e3821..dbf2675 100644 --- a/README.md +++ b/README.md @@ -134,11 +134,11 @@ An alternative to passing a `config` closure in the `options` array to `KernelTe is to use attributes for the kernel configuration. ```php +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureContainer; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterCompilerPass; 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; #[RegisterBundle(SomeBundle::class)] class SomeTest extends KernelTestCase @@ -164,8 +164,8 @@ You can also use the `RegisterBundle`, `ConfigureContainer`, `ConfigureExtension to configure the kernel in a data provider. ```php +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension; use Neusta\Pimcore\TestingFramework\KernelTestCase; -use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; class SomeTest extends KernelTestCase { @@ -199,11 +199,11 @@ class SomeTest extends KernelTestCase You can create your own kernel configuration attributes by implementing the `KernelConfiguration` interface: ```php -use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; +use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel; use Neusta\Pimcore\TestingFramework\TestKernel; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] -class ConfigureSomeBundle implements KernelConfiguration +class ConfigureSomeBundle implements ConfigureKernel { public function __construct( private readonly array $config, diff --git a/src/Attribute/ConfigureKernel.php b/src/Attribute/ConfigureKernel.php new file mode 100644 index 0000000..879e657 --- /dev/null +++ b/src/Attribute/ConfigureKernel.php @@ -0,0 +1,11 @@ +addTestConfig($this->config); + } +} diff --git a/src/Attribute/Kernel/ConfigureExtension.php b/src/Attribute/Kernel/ConfigureExtension.php new file mode 100644 index 0000000..4730bca --- /dev/null +++ b/src/Attribute/Kernel/ConfigureExtension.php @@ -0,0 +1,25 @@ + $extensionConfig + */ + public function __construct( + private readonly string $namespace, + private readonly array $extensionConfig, + ) { + } + + public function configure(TestKernel $kernel): void + { + $kernel->addTestExtensionConfig($this->namespace, $this->extensionConfig); + } +} diff --git a/src/Attribute/Kernel/RegisterBundle.php b/src/Attribute/Kernel/RegisterBundle.php new file mode 100644 index 0000000..bed4af8 --- /dev/null +++ b/src/Attribute/Kernel/RegisterBundle.php @@ -0,0 +1,25 @@ + $bundle + */ + public function __construct( + private readonly string $bundle, + ) { + } + + public function configure(TestKernel $kernel): void + { + $kernel->addTestBundle($this->bundle); + } +} diff --git a/src/Attribute/Kernel/RegisterCompilerPass.php b/src/Attribute/Kernel/RegisterCompilerPass.php new file mode 100644 index 0000000..ea096ae --- /dev/null +++ b/src/Attribute/Kernel/RegisterCompilerPass.php @@ -0,0 +1,28 @@ +addTestCompilerPass($this->compilerPass, $this->type, $this->priority); + } +} diff --git a/src/KernelTestCase.php b/src/KernelTestCase.php index f0ab0d6..22944f1 100644 --- a/src/KernelTestCase.php +++ b/src/KernelTestCase.php @@ -3,12 +3,11 @@ namespace Neusta\Pimcore\TestingFramework; -use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; use PHPUnit\Framework\TestCase; abstract class KernelTestCase extends \Pimcore\Test\KernelTestCase { - /** @var list */ + /** @var list */ private static iterable $kernelConfigurations = []; /** @@ -40,17 +39,17 @@ public function _getKernelConfigurationFromAttributes(): void $providedData = $this->getProvidedData(); $configurations = []; - foreach ($class->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + foreach ($class->getAttributes(ConfigureKernel::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { $configurations[] = $attribute->newInstance(); } - foreach ($method->getAttributes(KernelConfiguration::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + foreach ($method->getAttributes(ConfigureKernel::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { $configurations[] = $attribute->newInstance(); } if ([] !== $providedData) { foreach ($providedData as $data) { - if ($data instanceof KernelConfiguration) { + if ($data instanceof ConfigureKernel) { $configurations[] = $data; } } @@ -58,7 +57,7 @@ public function _getKernelConfigurationFromAttributes(): void // 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, + fn ($data) => !$data instanceof ConfigureKernel, ))); } diff --git a/src/Test/Attribute/ConfigureContainer.php b/src/Test/Attribute/ConfigureContainer.php index 7779c1f..0342964 100644 --- a/src/Test/Attribute/ConfigureContainer.php +++ b/src/Test/Attribute/ConfigureContainer.php @@ -3,22 +3,24 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\TestKernel; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureContainer as NewConfigureContainer; -#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -final class ConfigureContainer implements KernelConfiguration -{ +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" attribute is deprecated, use "%s" instead.', + ConfigureContainer::class, + NewConfigureContainer::class, +); + +class_alias(NewConfigureContainer::class, ConfigureContainer::class); + +if (false) { /** - * @param string|\Closure(ContainerBuilder):void $config path to a config file or a closure which gets the {@see ContainerBuilder} as its first argument + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureContainer instead */ - public function __construct( - private readonly string|\Closure $config, - ) { - } - - public function configure(TestKernel $kernel): void + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] + class ConfigureContainer { - $kernel->addTestConfig($this->config); } } diff --git a/src/Test/Attribute/ConfigureExtension.php b/src/Test/Attribute/ConfigureExtension.php index 04b2ebc..48aab85 100644 --- a/src/Test/Attribute/ConfigureExtension.php +++ b/src/Test/Attribute/ConfigureExtension.php @@ -3,22 +3,24 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\TestKernel; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension as NewConfigureExtension; -#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -final class ConfigureExtension implements KernelConfiguration -{ +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" attribute is deprecated, use "%s" instead.', + ConfigureExtension::class, + NewConfigureExtension::class, +); + +class_alias(NewConfigureExtension::class, ConfigureExtension::class); + +if (false) { /** - * @param array $extensionConfig + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension instead */ - public function __construct( - private readonly string $namespace, - private readonly array $extensionConfig, - ) { - } - - public function configure(TestKernel $kernel): void + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] + class ConfigureExtension { - $kernel->addTestExtensionConfig($this->namespace, $this->extensionConfig); } } diff --git a/src/Test/Attribute/KernelConfiguration.php b/src/Test/Attribute/KernelConfiguration.php index 99a17d4..68e8816 100644 --- a/src/Test/Attribute/KernelConfiguration.php +++ b/src/Test/Attribute/KernelConfiguration.php @@ -3,9 +3,23 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\TestKernel; +use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel; -interface KernelConfiguration -{ - public function configure(TestKernel $kernel): void; +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" interface is deprecated, use "%s" instead.', + KernelConfiguration::class, + ConfigureKernel::class, +); + +class_alias(ConfigureKernel::class, KernelConfiguration::class); + +if (false) { + /** + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel instead + */ + interface KernelConfiguration extends ConfigureKernel + { + } } diff --git a/src/Test/Attribute/RegisterBundle.php b/src/Test/Attribute/RegisterBundle.php index c0f3300..8099eb9 100644 --- a/src/Test/Attribute/RegisterBundle.php +++ b/src/Test/Attribute/RegisterBundle.php @@ -3,22 +3,24 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\TestKernel; -use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle as NewRegisterBundle; -#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -final class RegisterBundle implements KernelConfiguration -{ +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" attribute is deprecated, use "%s" instead.', + RegisterBundle::class, + NewRegisterBundle::class, +); + +class_alias(NewRegisterBundle::class, RegisterBundle::class); + +if (false) { /** - * @param class-string $bundle + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle instead */ - public function __construct( - private readonly string $bundle, - ) { - } - - public function configure(TestKernel $kernel): void + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] + class RegisterBundle { - $kernel->addTestBundle($this->bundle); } } diff --git a/src/Test/Attribute/RegisterCompilerPass.php b/src/Test/Attribute/RegisterCompilerPass.php index 1c6fc26..b8710c1 100644 --- a/src/Test/Attribute/RegisterCompilerPass.php +++ b/src/Test/Attribute/RegisterCompilerPass.php @@ -3,25 +3,24 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\TestKernel; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterCompilerPass as NewRegisterCompilerPass; -#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -final class RegisterCompilerPass implements KernelConfiguration -{ +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" attribute is deprecated, use "%s" instead.', + RegisterCompilerPass::class, + NewRegisterCompilerPass::class, +); + +class_alias(NewRegisterCompilerPass::class, RegisterCompilerPass::class); + +if (false) { /** - * @param PassConfig::TYPE_* $type + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterCompilerPass instead */ - public function __construct( - private readonly CompilerPassInterface $compilerPass, - private readonly string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, - private readonly int $priority = 0, - ) { - } - - public function configure(TestKernel $kernel): void + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] + class RegisterCompilerPass { - $kernel->addTestCompilerPass($this->compilerPass, $this->type, $this->priority); } } diff --git a/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php b/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php index 561a395..36f211b 100644 --- a/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php +++ b/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php @@ -3,12 +3,12 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Fixtures\Attribute; -use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; +use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] -final class ConfigureConfigurationBundle implements KernelConfiguration +final class ConfigureConfigurationBundle implements ConfigureKernel { public function __construct( private readonly array $config, diff --git a/tests/Functional/CompilerPassTest.php b/tests/Functional/CompilerPassTest.php index c009a2e..351d7bc 100644 --- a/tests/Functional/CompilerPassTest.php +++ b/tests/Functional/CompilerPassTest.php @@ -3,8 +3,8 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterCompilerPass; use Neusta\Pimcore\TestingFramework\KernelTestCase; -use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterCompilerPass; 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; diff --git a/tests/Functional/ContainerConfigurationTest.php b/tests/Functional/ContainerConfigurationTest.php index d64435f..252bd61 100644 --- a/tests/Functional/ContainerConfigurationTest.php +++ b/tests/Functional/ContainerConfigurationTest.php @@ -3,9 +3,9 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureContainer; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle; use Neusta\Pimcore\TestingFramework\KernelTestCase; -use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureContainer; -use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; diff --git a/tests/Functional/DataProviderTest.php b/tests/Functional/DataProviderTest.php index 5b0ce29..eba2c6e 100644 --- a/tests/Functional/DataProviderTest.php +++ b/tests/Functional/DataProviderTest.php @@ -3,9 +3,9 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle; use Neusta\Pimcore\TestingFramework\KernelTestCase; -use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; -use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; final class DataProviderTest extends KernelTestCase diff --git a/tests/Functional/ExtensionConfigurationTest.php b/tests/Functional/ExtensionConfigurationTest.php index 24e1a78..65294d4 100644 --- a/tests/Functional/ExtensionConfigurationTest.php +++ b/tests/Functional/ExtensionConfigurationTest.php @@ -3,9 +3,9 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\ConfigureExtension; +use Neusta\Pimcore\TestingFramework\Attribute\Kernel\RegisterBundle; use Neusta\Pimcore\TestingFramework\KernelTestCase; -use Neusta\Pimcore\TestingFramework\Test\Attribute\ConfigureExtension; -use Neusta\Pimcore\TestingFramework\Test\Attribute\RegisterBundle; use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle;