From 4dd05ca8b217eefcc3d92c668c26c6450c323ff7 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 17:18:44 +0200 Subject: [PATCH 1/6] use Pimcore\Test\KernelTestCase instead of Symfony\Bundle\FrameworkBundle\Test\KernelTestCase --- src/Database/ResetDatabase.php | 2 +- src/Exception/DoesNotExtendKernelTestCase.php | 4 ++-- src/Pimcore/WithoutCache.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Database/ResetDatabase.php b/src/Database/ResetDatabase.php index 5ea6039..12fb611 100644 --- a/src/Database/ResetDatabase.php +++ b/src/Database/ResetDatabase.php @@ -6,7 +6,7 @@ use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; use Neusta\Pimcore\TestingFramework\Exception\DoesNotExtendKernelTestCase; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Pimcore\Test\KernelTestCase; /** * @mixin KernelTestCase diff --git a/src/Exception/DoesNotExtendKernelTestCase.php b/src/Exception/DoesNotExtendKernelTestCase.php index a4b2ab0..eda87d7 100644 --- a/src/Exception/DoesNotExtendKernelTestCase.php +++ b/src/Exception/DoesNotExtendKernelTestCase.php @@ -4,7 +4,7 @@ namespace Neusta\Pimcore\TestingFramework\Exception; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Pimcore\Test\KernelTestCase; final class DoesNotExtendKernelTestCase extends \RuntimeException { @@ -13,7 +13,7 @@ public static function forTrait(string $trait): self return new self(\sprintf( 'The trait "%s" can only be used on TestCases that extend "%s".', $trait, - KernelTestCase::class + KernelTestCase::class, )); } } diff --git a/src/Pimcore/WithoutCache.php b/src/Pimcore/WithoutCache.php index a95d2b5..e524c11 100644 --- a/src/Pimcore/WithoutCache.php +++ b/src/Pimcore/WithoutCache.php @@ -6,7 +6,7 @@ use Neusta\Pimcore\TestingFramework\Exception\DoesNotExtendKernelTestCase; use Pimcore\Cache; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Pimcore\Test\KernelTestCase; /** * @mixin KernelTestCase From 706e0fd3fc9da1c4a96acd1b1cee278b456e7d51 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 17:38:56 +0200 Subject: [PATCH 2/6] Move "Kernel\TestKernel" to the namespace root --- CHANGELOG.md | 4 + README.md | 6 +- composer-dependency-analyser.php | 3 + composer.json | 1 + phpstan.neon | 2 + src/Kernel/TestKernel.php | 121 ++--------------- src/Test/Attribute/ConfigureContainer.php | 2 +- src/Test/Attribute/ConfigureExtension.php | 2 +- src/Test/Attribute/KernelConfiguration.php | 2 +- src/Test/Attribute/RegisterBundle.php | 2 +- src/Test/Attribute/RegisterCompilerPass.php | 2 +- src/Test/ConfigurableKernelTestCase.php | 2 +- src/TestKernel.php | 123 ++++++++++++++++++ .../ConfigureConfigurationBundle.php | 2 +- tests/Functional/CompilerPassTest.php | 2 +- .../Functional/ContainerConfigurationTest.php | 2 +- .../Functional/ExtensionConfigurationTest.php | 2 +- tests/Functional/KernelShutdownTest.php | 2 +- tests/bootstrap.php | 2 +- 19 files changed, 160 insertions(+), 124 deletions(-) create mode 100644 src/TestKernel.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5186925..f10c971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.13.0 +### Changes: +- Deprecated `Neusta\Pimcore\TestingFramework\Kernel\TestKernel` in favor of `Neusta\Pimcore\TestingFramework\TestKernel` + ## v0.12.4 ### Bugfixes: - Fix type definition for `ConfgureExtension` diff --git a/README.md b/README.md index f888d65..d58161f 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ For a basic setup, you can use the `TestKernel` directly: # tests/bootstrap.php addPathToExclude(__DIR__ . '/tests/app') + // Ignore packages that the analyzer does not recognize + ->ignoreErrorsOnPackage('symfony/deprecation-contracts', [ErrorType::UNUSED_DEPENDENCY]) + // Ignore optional dependency ->ignoreErrorsOnPackageAndPath('dama/doctrine-test-bundle', __DIR__ . '/src/Database/ResetDatabase.php', [ErrorType::DEV_DEPENDENCY_IN_PROD]) ->ignoreErrorsOnPackageAndPath('dama/doctrine-test-bundle', __DIR__ . '/src/Database/DatabaseResetter.php', [ErrorType::DEV_DEPENDENCY_IN_PROD]) diff --git a/composer.json b/composer.json index cfabe98..a18419a 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/config": "^5.4 || ^6.4", "symfony/console": "^5.4 || ^6.4", "symfony/dependency-injection": "^5.4 || ^6.4", + "symfony/deprecation-contracts": "^2.1 || ^3.0", "symfony/event-dispatcher": "^5.4 || ^6.4", "symfony/filesystem": "^5.4 || ^6.4", "symfony/framework-bundle": "^5.4 || ^6.4", diff --git a/phpstan.neon b/phpstan.neon index 4cf2190..14e1e08 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,6 +11,8 @@ parameters: excludePaths: # There are two errors, that were not able to be added to the baseline - src/Kernel/CompatibilityKernel.php + # Deprecated aliases + - src/Kernel/TestKernel.php bootstrapFiles: - vendor/pimcore/pimcore/stubs/dynamic-constants.php diff --git a/src/Kernel/TestKernel.php b/src/Kernel/TestKernel.php index 6da5ed4..4870faf 100644 --- a/src/Kernel/TestKernel.php +++ b/src/Kernel/TestKernel.php @@ -3,120 +3,23 @@ namespace Neusta\Pimcore\TestingFramework\Kernel; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Neusta\Pimcore\TestingFramework\TestKernel as RootTestKernel; -class TestKernel extends CompatibilityKernel -{ - private bool $dynamicCache = false; - /** @var list> */ - private array $testBundles = []; - /** @var list */ - private array $testCompilerPasses = []; +trigger_deprecation( + 'teamneusta/pimcore-testing-framework', + '0.13', + 'The "%s" class is deprecated, use "%s" instead.', + TestKernel::class, + RootTestKernel::class, +); - /** - * @param class-string $bundleClass - */ - public function addTestBundle(string $bundleClass): void - { - $this->testBundles[] = $bundleClass; - $this->dynamicCache = true; - } - - /** - * @param string|callable(ContainerBuilder):void $config path to a config file or a callable which gets the {@see ContainerBuilder} as its first argument - */ - public function addTestConfig(string|callable $config): void - { - $this->testConfigs[] = $config; - $this->dynamicCache = true; - } - - /** - * @param array $config - */ - public function addTestExtensionConfig(string $namespace, array $config): void - { - $this->testExtensionConfigs[$namespace] = $config; - $this->dynamicCache = true; - } - - /** - * @param PassConfig::TYPE_* $type - */ - public function addTestCompilerPass( - CompilerPassInterface $compilerPass, - string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, - int $priority = 0, - ): void { - $this->testCompilerPasses[] = [$compilerPass, $type, $priority]; - $this->dynamicCache = true; - } - - /** - * @param array{config?: callable(static):void, ...} $options - */ - public function handleOptions(array $options): void - { - if (\is_callable($configure = $options['config'] ?? null)) { - $configure($this); - } - } - - public function getCacheDir(): string - { - if ($this->dynamicCache) { - return rtrim(parent::getCacheDir(), '/') . '/' . spl_object_hash($this); - } - - return parent::getCacheDir(); - } +class_alias(RootTestKernel::class, TestKernel::class); +if (false) { /** - * @return array + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\TestKernel instead */ - public function registerBundles(): array - { - $bundles = parent::registerBundles(); - - if ([] === $this->testBundles) { - return $bundles; - } - - $bundleClasses = []; - foreach ($bundles as $bundle) { - $bundleClasses[$bundle::class] = true; - } - - foreach (array_unique($this->testBundles) as $class) { - if (!isset($bundleClasses[$class])) { - $bundles[] = new $class(); - } - } - - return $bundles; - } - - protected function buildContainer(): ContainerBuilder - { - $container = parent::buildContainer(); - - foreach ($this->testCompilerPasses as $compilerPass) { - $container->addCompilerPass(...$compilerPass); - } - - return $container; - } - - public function shutdown(): void + class TestKernel extends RootTestKernel { - parent::shutdown(); - - if ($this->dynamicCache) { - (new Filesystem())->remove($this->getCacheDir()); - } } } diff --git a/src/Test/Attribute/ConfigureContainer.php b/src/Test/Attribute/ConfigureContainer.php index a7d2a04..7779c1f 100644 --- a/src/Test/Attribute/ConfigureContainer.php +++ b/src/Test/Attribute/ConfigureContainer.php @@ -3,7 +3,7 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\TestKernel; use Symfony\Component\DependencyInjection\ContainerBuilder; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Test/Attribute/ConfigureExtension.php b/src/Test/Attribute/ConfigureExtension.php index 022a445..04b2ebc 100644 --- a/src/Test/Attribute/ConfigureExtension.php +++ b/src/Test/Attribute/ConfigureExtension.php @@ -3,7 +3,7 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\TestKernel; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] final class ConfigureExtension implements KernelConfiguration diff --git a/src/Test/Attribute/KernelConfiguration.php b/src/Test/Attribute/KernelConfiguration.php index cee4bba..99a17d4 100644 --- a/src/Test/Attribute/KernelConfiguration.php +++ b/src/Test/Attribute/KernelConfiguration.php @@ -3,7 +3,7 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\TestKernel; interface KernelConfiguration { diff --git a/src/Test/Attribute/RegisterBundle.php b/src/Test/Attribute/RegisterBundle.php index 9c7c231..c0f3300 100644 --- a/src/Test/Attribute/RegisterBundle.php +++ b/src/Test/Attribute/RegisterBundle.php @@ -3,7 +3,7 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\TestKernel; use Symfony\Component\HttpKernel\Bundle\BundleInterface; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Test/Attribute/RegisterCompilerPass.php b/src/Test/Attribute/RegisterCompilerPass.php index 2b73068..1c6fc26 100644 --- a/src/Test/Attribute/RegisterCompilerPass.php +++ b/src/Test/Attribute/RegisterCompilerPass.php @@ -3,7 +3,7 @@ namespace Neusta\Pimcore\TestingFramework\Test\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; +use Neusta\Pimcore\TestingFramework\TestKernel; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\PassConfig; diff --git a/src/Test/ConfigurableKernelTestCase.php b/src/Test/ConfigurableKernelTestCase.php index 0075c70..2297818 100644 --- a/src/Test/ConfigurableKernelTestCase.php +++ b/src/Test/ConfigurableKernelTestCase.php @@ -3,8 +3,8 @@ namespace Neusta\Pimcore\TestingFramework\Test; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; +use Neusta\Pimcore\TestingFramework\TestKernel; use PHPUnit\Framework\TestCase; use Pimcore\Test\KernelTestCase; diff --git a/src/TestKernel.php b/src/TestKernel.php new file mode 100644 index 0000000..f3ec1ca --- /dev/null +++ b/src/TestKernel.php @@ -0,0 +1,123 @@ +> */ + private array $testBundles = []; + /** @var list */ + private array $testCompilerPasses = []; + + /** + * @param class-string $bundleClass + */ + public function addTestBundle(string $bundleClass): void + { + $this->testBundles[] = $bundleClass; + $this->dynamicCache = true; + } + + /** + * @param string|callable(ContainerBuilder):void $config path to a config file or a callable which gets the {@see ContainerBuilder} as its first argument + */ + public function addTestConfig(string|callable $config): void + { + $this->testConfigs[] = $config; + $this->dynamicCache = true; + } + + /** + * @param array $config + */ + public function addTestExtensionConfig(string $namespace, array $config): void + { + $this->testExtensionConfigs[$namespace] = $config; + $this->dynamicCache = true; + } + + /** + * @param PassConfig::TYPE_* $type + */ + public function addTestCompilerPass( + CompilerPassInterface $compilerPass, + string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, + int $priority = 0, + ): void { + $this->testCompilerPasses[] = [$compilerPass, $type, $priority]; + $this->dynamicCache = true; + } + + /** + * @param array{config?: callable(static):void, ...} $options + */ + public function handleOptions(array $options): void + { + if (\is_callable($configure = $options['config'] ?? null)) { + $configure($this); + } + } + + public function getCacheDir(): string + { + if ($this->dynamicCache) { + return rtrim(parent::getCacheDir(), '/') . '/' . spl_object_hash($this); + } + + return parent::getCacheDir(); + } + + /** + * @return array + */ + public function registerBundles(): array + { + $bundles = parent::registerBundles(); + + if ([] === $this->testBundles) { + return $bundles; + } + + $bundleClasses = []; + foreach ($bundles as $bundle) { + $bundleClasses[$bundle::class] = true; + } + + foreach (array_unique($this->testBundles) as $class) { + if (!isset($bundleClasses[$class])) { + $bundles[] = new $class(); + } + } + + return $bundles; + } + + protected function buildContainer(): ContainerBuilder + { + $container = parent::buildContainer(); + + foreach ($this->testCompilerPasses as $compilerPass) { + $container->addCompilerPass(...$compilerPass); + } + + return $container; + } + + public function shutdown(): void + { + parent::shutdown(); + + if ($this->dynamicCache) { + (new Filesystem())->remove($this->getCacheDir()); + } + } +} diff --git a/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php b/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php index e6175af..561a395 100644 --- a/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php +++ b/tests/Fixtures/Attribute/ConfigureConfigurationBundle.php @@ -3,8 +3,8 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Fixtures\Attribute; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; +use Neusta\Pimcore\TestingFramework\TestKernel; use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] diff --git a/tests/Functional/CompilerPassTest.php b/tests/Functional/CompilerPassTest.php index 687dc61..db79faf 100644 --- a/tests/Functional/CompilerPassTest.php +++ b/tests/Functional/CompilerPassTest.php @@ -3,9 +3,9 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; 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; diff --git a/tests/Functional/ContainerConfigurationTest.php b/tests/Functional/ContainerConfigurationTest.php index 6c4ced0..fbdc838 100644 --- a/tests/Functional/ContainerConfigurationTest.php +++ b/tests/Functional/ContainerConfigurationTest.php @@ -3,10 +3,10 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; 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; diff --git a/tests/Functional/ExtensionConfigurationTest.php b/tests/Functional/ExtensionConfigurationTest.php index 38f39f4..885b53c 100644 --- a/tests/Functional/ExtensionConfigurationTest.php +++ b/tests/Functional/ExtensionConfigurationTest.php @@ -3,10 +3,10 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; 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 diff --git a/tests/Functional/KernelShutdownTest.php b/tests/Functional/KernelShutdownTest.php index 6edfe56..4bc4afd 100644 --- a/tests/Functional/KernelShutdownTest.php +++ b/tests/Functional/KernelShutdownTest.php @@ -3,8 +3,8 @@ namespace Neusta\Pimcore\TestingFramework\Tests\Functional; -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; +use Neusta\Pimcore\TestingFramework\TestKernel; use Symfony\Component\Filesystem\Filesystem; class KernelShutdownTest extends ConfigurableKernelTestCase diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3083da1..72cebf5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,8 +2,8 @@ declare(strict_types=1); -use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; use Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore; +use Neusta\Pimcore\TestingFramework\TestKernel; include dirname(__DIR__) . '/vendor/autoload.php'; From 034834a31cf03c2da555ee4b0d66c14671f2c235 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 17:43:07 +0200 Subject: [PATCH 3/6] Move "Kernel\CompatibilityKernel" to "Internal\CompatibilityTestKernel" --- phpstan.neon | 2 +- .../CompatibilityTestKernel.php} | 6 +++--- src/TestKernel.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/{Kernel/CompatibilityKernel.php => Internal/CompatibilityTestKernel.php} (95%) diff --git a/phpstan.neon b/phpstan.neon index 14e1e08..d37fe1d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,7 +10,7 @@ parameters: excludePaths: # There are two errors, that were not able to be added to the baseline - - src/Kernel/CompatibilityKernel.php + - src/Internal/CompatibilityTestKernel.php # Deprecated aliases - src/Kernel/TestKernel.php diff --git a/src/Kernel/CompatibilityKernel.php b/src/Internal/CompatibilityTestKernel.php similarity index 95% rename from src/Kernel/CompatibilityKernel.php rename to src/Internal/CompatibilityTestKernel.php index c24df66..65f5b58 100644 --- a/src/Kernel/CompatibilityKernel.php +++ b/src/Internal/CompatibilityTestKernel.php @@ -1,7 +1,7 @@ > */ From a69df050717e1ba49ea698c0a4e2e76418c0ae88 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 17:54:44 +0200 Subject: [PATCH 4/6] Move "Pimcore\BootstrapPimcore" to the namespace root --- CHANGELOG.md | 1 + README.md | 6 ++--- phpstan-baseline.neon | 4 ++-- phpstan.neon | 1 + src/BootstrapPimcore.php | 31 ++++++++++++++++++++++++++ src/Pimcore/BootstrapPimcore.php | 38 +++++++++++++++++--------------- tests/bootstrap.php | 2 +- 7 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 src/BootstrapPimcore.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f10c971..33e17b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 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` ## v0.12.4 ### Bugfixes: diff --git a/README.md b/README.md index d58161f..99c35be 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,14 @@ Just call `BootstrapPimcore::bootstrap()` in your `tests/bootstrap.php` as seen include dirname(__DIR__).'/vendor/autoload.php'; -Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore::bootstrap(); +\Neusta\Pimcore\TestingFramework\BootstrapPimcore::bootstrap(); ``` You can also pass any environment variable via named arguments to this method: ```php # tests/bootstrap.php -Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore::bootstrap( +\Neusta\Pimcore\TestingFramework\BootstrapPimcore::bootstrap( APP_ENV: 'custom', SOMETHING: 'else', ); @@ -52,7 +52,7 @@ For a basic setup, you can use the `TestKernel` directly: # tests/bootstrap.php 'test', + ]; + + public static function bootstrap(string ...$envVars): void + { + foreach ($envVars + self::DEFAULT_ENV_VARS as $name => $value) { + self::setEnv($name, $value); + } + + Bootstrap::setProjectRoot(); + Bootstrap::bootstrap(); + AdminMode::disable(); + } + + public static function setEnv(string $name, string $value): void + { + putenv("{$name}=" . $_ENV[$name] = $_SERVER[$name] = $value); + } +} diff --git a/src/Pimcore/BootstrapPimcore.php b/src/Pimcore/BootstrapPimcore.php index 5699435..f68dc84 100644 --- a/src/Pimcore/BootstrapPimcore.php +++ b/src/Pimcore/BootstrapPimcore.php @@ -1,30 +1,32 @@ 'test', - ]; +class_alias(RootBootstrapPimcore::class, BootstrapPimcore::class); - public static function bootstrap(string ...$envVars): void +if (false) { + /** + * @deprecated since 0.13, use Neusta\Pimcore\TestingFramework\BootstrapPimcore instead + */ + final class BootstrapPimcore { - foreach ($envVars + self::DEFAULT_ENV_VARS as $name => $value) { - self::setEnv($name, $value); + public static function bootstrap(string ...$envVars): void + { } - Bootstrap::setProjectRoot(); - Bootstrap::bootstrap(); - AdminMode::disable(); - } - - public static function setEnv(string $name, string $value): void - { - putenv("{$name}=" . $_ENV[$name] = $_SERVER[$name] = $value); + public static function setEnv(string $name, string $value): void + { + } } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 72cebf5..0afdca9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore; +use Neusta\Pimcore\TestingFramework\BootstrapPimcore; use Neusta\Pimcore\TestingFramework\TestKernel; include dirname(__DIR__) . '/vendor/autoload.php'; From b6dd1c81b5c38f1f1cad1fe3bf7ffa78672a4227 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 18:09:22 +0200 Subject: [PATCH 5/6] Move "Test\ConfigurableKernelTestCase" as "KernelTestCase" to the namespace root --- CHANGELOG.md | 1 + README.md | 16 ++-- src/KernelTestCase.php | 73 ++++++++++++++++++ src/Test/ConfigurableKernelTestCase.php | 74 +++---------------- tests/Functional/CompilerPassTest.php | 4 +- .../Functional/ContainerConfigurationTest.php | 4 +- tests/Functional/CustomAttributeTest.php | 4 +- tests/Functional/DataProviderTest.php | 4 +- .../Functional/ExtensionConfigurationTest.php | 4 +- tests/Functional/KernelShutdownTest.php | 4 +- 10 files changed, 106 insertions(+), 82 deletions(-) create mode 100644 src/KernelTestCase.php 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 From 9370cc548b78e8d6a0094dcb94ce7e4a0fb72d50 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 18:35:38 +0200 Subject: [PATCH 6/6] Rename "Test\Attribute\KernelConfiguration" to "Attribute\ConfigureKernel" and move its implementations from "Test\Attribute\" to "Attribute\Kernel\" --- CHANGELOG.md | 13 ++++++-- README.md | 14 ++++----- phpstan.neon | 1 + src/Attribute/ConfigureKernel.php | 11 +++++++ src/Attribute/Kernel/ConfigureContainer.php | 25 +++++++++++++++ src/Attribute/Kernel/ConfigureExtension.php | 25 +++++++++++++++ src/Attribute/Kernel/RegisterBundle.php | 25 +++++++++++++++ src/Attribute/Kernel/RegisterCompilerPass.php | 28 +++++++++++++++++ src/KernelTestCase.php | 12 +++---- src/Test/Attribute/ConfigureContainer.php | 28 +++++++++-------- src/Test/Attribute/ConfigureExtension.php | 28 +++++++++-------- src/Test/Attribute/KernelConfiguration.php | 22 ++++++++++--- src/Test/Attribute/RegisterBundle.php | 28 +++++++++-------- src/Test/Attribute/RegisterCompilerPass.php | 31 +++++++++---------- .../ConfigureConfigurationBundle.php | 4 +-- tests/Functional/CompilerPassTest.php | 2 +- .../Functional/ContainerConfigurationTest.php | 4 +-- tests/Functional/DataProviderTest.php | 4 +-- .../Functional/ExtensionConfigurationTest.php | 4 +-- 19 files changed, 225 insertions(+), 84 deletions(-) create mode 100644 src/Attribute/ConfigureKernel.php create mode 100644 src/Attribute/Kernel/ConfigureContainer.php create mode 100644 src/Attribute/Kernel/ConfigureExtension.php create mode 100644 src/Attribute/Kernel/RegisterBundle.php create mode 100644 src/Attribute/Kernel/RegisterCompilerPass.php 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/phpstan.neon b/phpstan.neon index fc47051..c018e1d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,6 +14,7 @@ parameters: # Deprecated aliases - src/Kernel/TestKernel.php - src/Pimcore/BootstrapPimcore.php + - src/Test/* bootstrapFiles: - vendor/pimcore/pimcore/stubs/dynamic-constants.php 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..37ab67c 100644 --- a/src/KernelTestCase.php +++ b/src/KernelTestCase.php @@ -3,12 +3,12 @@ namespace Neusta\Pimcore\TestingFramework; -use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; +use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel; use PHPUnit\Framework\TestCase; abstract class KernelTestCase extends \Pimcore\Test\KernelTestCase { - /** @var list */ + /** @var list */ private static iterable $kernelConfigurations = []; /** @@ -40,17 +40,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 +58,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;