From a354c9b12e43eb12180a6389f2ce57c468ad179d Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 30 Aug 2024 17:00:47 +0200 Subject: [PATCH] Extract ConfigureKernel trait --- src/Internal/ConfigureKernel.php | 60 ++++++++++++++++++++++++++++++++ src/KernelTestCase.php | 40 ++------------------- 2 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 src/Internal/ConfigureKernel.php diff --git a/src/Internal/ConfigureKernel.php b/src/Internal/ConfigureKernel.php new file mode 100644 index 0000000..3691a67 --- /dev/null +++ b/src/Internal/ConfigureKernel.php @@ -0,0 +1,60 @@ +handleOptions($options); + + return $kernel; + } + + /** + * @internal + * + * @before + */ + public function _collectKernelConfigurations(): void + { + if (!$this instanceof KernelTestCase) { + throw DoesNotExtendKernelTestCase::forTrait(__TRAIT__); + } + + KernelConfigurator::up($this); + } + + /** + * @internal + * + * @after + */ + public function _resetKernelConfigurations(): void + { + KernelConfigurator::down(); + } +} diff --git a/src/KernelTestCase.php b/src/KernelTestCase.php index 8eaf7e5..9c3a69f 100644 --- a/src/KernelTestCase.php +++ b/src/KernelTestCase.php @@ -3,45 +3,9 @@ namespace Neusta\Pimcore\TestingFramework; -use Neusta\Pimcore\TestingFramework\Internal\KernelConfigurator; +use Neusta\Pimcore\TestingFramework\Internal\ConfigureKernel; abstract class KernelTestCase extends \Pimcore\Test\KernelTestCase { - /** - * @param array{config?: callable(TestKernel):void, environment?: string, debug?: bool, ...} $options - */ - protected static function createKernel(array $options = []): TestKernel - { - $kernel = parent::createKernel($options); - - if (!$kernel instanceof TestKernel) { - throw new \LogicException(sprintf('Kernel must be an instance of %s', TestKernel::class)); - } - - KernelConfigurator::configure($kernel); - - $kernel->handleOptions($options); - - return $kernel; - } - - /** - * @internal - * - * @before - */ - public function _collectKernelConfigurations(): void - { - KernelConfigurator::up($this); - } - - /** - * @internal - * - * @after - */ - public function _resetKernelConfigurations(): void - { - KernelConfigurator::down(); - } + use ConfigureKernel; }