-
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.
Describe and test custom kernel configuration attributes (#13)
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\TestingFramework\Tests\Fixtures\Attribute; | ||
|
||
use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; | ||
use Neusta\Pimcore\TestingFramework\Test\Attribute\KernelConfiguration; | ||
use Neusta\Pimcore\TestingFramework\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] | ||
final class ConfigureConfigurationBundle implements KernelConfiguration | ||
{ | ||
public function __construct( | ||
private readonly array $config, | ||
) { | ||
} | ||
|
||
public function configure(TestKernel $kernel): void | ||
{ | ||
$kernel->addTestBundle(ConfigurationBundle::class); | ||
$kernel->addTestExtensionConfig('configuration', array_merge( | ||
['bar' => ['value2', 'value3']], | ||
$this->config, | ||
)); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\TestingFramework\Tests\Functional; | ||
|
||
use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; | ||
use Neusta\Pimcore\TestingFramework\Tests\Fixtures\Attribute\ConfigureConfigurationBundle; | ||
|
||
final class CustomAttributeTest extends ConfigurableKernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
#[ConfigureConfigurationBundle(['foo' => 'value1'])] | ||
public function configuration_via_attribute(): void | ||
{ | ||
$container = self::getContainer(); | ||
|
||
self::assertSame('value1', $container->getParameter('configuration.foo')); | ||
self::assertSame(['value2', 'value3'], $container->getParameter('configuration.bar')); | ||
} | ||
|
||
public function provideData(): iterable | ||
{ | ||
yield [new ConfigureConfigurationBundle(['foo' => 'test1', 'bar' => ['test2', 'test3']])]; | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider provideData | ||
*/ | ||
public function configuration_via_data_provider(): void | ||
{ | ||
$container = self::getContainer(); | ||
|
||
self::assertSame('test1', $container->getParameter('configuration.foo')); | ||
self::assertSame(['test2', 'test3'], $container->getParameter('configuration.bar')); | ||
} | ||
} |