-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move "Test\ConfigurableKernelTestCase" as "KernelTestCase" to the nam…
…espace root
- Loading branch information
Showing
10 changed files
with
106 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\TestingFramework; | ||
|
||
use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class KernelTestCase extends \Pimcore\Test\KernelTestCase | ||
{ | ||
/** @var list<KernelConfiguration> */ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters