Skip to content

Commit

Permalink
Rename "Test\Attribute\KernelConfiguration" to "Attribute\ConfigureKe…
Browse files Browse the repository at this point in the history
…rnel" and move its implementations from "Test\Attribute\" to "Attribute\Kernel\"
  • Loading branch information
jdreesen committed Aug 30, 2024
1 parent b6dd1c8 commit 9370cc5
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 84 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Attribute/ConfigureKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\TestingFramework\Attribute;

use Neusta\Pimcore\TestingFramework\TestKernel;

interface ConfigureKernel
{
public function configure(TestKernel $kernel): void;
}
25 changes: 25 additions & 0 deletions src/Attribute/Kernel/ConfigureContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\TestingFramework\Attribute\Kernel;

use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel;
use Neusta\Pimcore\TestingFramework\TestKernel;
use Symfony\Component\DependencyInjection\ContainerBuilder;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
final class ConfigureContainer implements ConfigureKernel
{
/**
* @param string|\Closure(ContainerBuilder):void $config path to a config file or a closure which gets the {@see ContainerBuilder} as its first argument
*/
public function __construct(
private readonly string|\Closure $config,
) {
}

public function configure(TestKernel $kernel): void
{
$kernel->addTestConfig($this->config);
}
}
25 changes: 25 additions & 0 deletions src/Attribute/Kernel/ConfigureExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\TestingFramework\Attribute\Kernel;

use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel;
use Neusta\Pimcore\TestingFramework\TestKernel;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
final class ConfigureExtension implements ConfigureKernel
{
/**
* @param array<string, mixed> $extensionConfig
*/
public function __construct(
private readonly string $namespace,
private readonly array $extensionConfig,
) {
}

public function configure(TestKernel $kernel): void
{
$kernel->addTestExtensionConfig($this->namespace, $this->extensionConfig);
}
}
25 changes: 25 additions & 0 deletions src/Attribute/Kernel/RegisterBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\TestingFramework\Attribute\Kernel;

use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel;
use Neusta\Pimcore\TestingFramework\TestKernel;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
final class RegisterBundle implements ConfigureKernel
{
/**
* @param class-string<BundleInterface> $bundle
*/
public function __construct(
private readonly string $bundle,
) {
}

public function configure(TestKernel $kernel): void
{
$kernel->addTestBundle($this->bundle);
}
}
28 changes: 28 additions & 0 deletions src/Attribute/Kernel/RegisterCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\TestingFramework\Attribute\Kernel;

use Neusta\Pimcore\TestingFramework\Attribute\ConfigureKernel;
use Neusta\Pimcore\TestingFramework\TestKernel;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
final class RegisterCompilerPass implements ConfigureKernel
{
/**
* @param PassConfig::TYPE_* $type
*/
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
{
$kernel->addTestCompilerPass($this->compilerPass, $this->type, $this->priority);
}
}
12 changes: 6 additions & 6 deletions src/KernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<KernelConfiguration> */
/** @var list<ConfigureKernel> */
private static iterable $kernelConfigurations = [];

/**
Expand Down Expand Up @@ -40,25 +40,25 @@ 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;
}
}

// 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,
)));
}

Expand Down
28 changes: 15 additions & 13 deletions src/Test/Attribute/ConfigureContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
28 changes: 15 additions & 13 deletions src/Test/Attribute/ConfigureExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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);
}
}
22 changes: 18 additions & 4 deletions src/Test/Attribute/KernelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
28 changes: 15 additions & 13 deletions src/Test/Attribute/RegisterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<BundleInterface> $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);
}
}
Loading

0 comments on commit 9370cc5

Please sign in to comment.