-
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.
- Loading branch information
Showing
11 changed files
with
159 additions
and
3 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
10 changes: 10 additions & 0 deletions
10
tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php
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,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Fixtures\ConfigurationBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
final class ConfigurationBundle extends Bundle | ||
{ | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Fixtures/ConfigurationBundle/DependencyInjection/Configuration.php
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 Fixtures\ConfigurationBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
final class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$tree = new TreeBuilder('configuration'); | ||
|
||
$tree->getRootNode() | ||
->children() | ||
->scalarNode('foo')->isRequired()->end() | ||
->arrayNode('bar') | ||
->isRequired() | ||
->scalarPrototype() | ||
->end() | ||
->end(); | ||
|
||
return $tree; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/Fixtures/ConfigurationBundle/DependencyInjection/ConfigurationExtension.php
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,16 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Fixtures\ConfigurationBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; | ||
|
||
final class ConfigurationExtension extends ConfigurableExtension | ||
{ | ||
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void | ||
{ | ||
$container->setParameter('configuration.foo', $mergedConfig['foo']); | ||
$container->setParameter('configuration.bar', $mergedConfig['bar']); | ||
} | ||
} |
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,12 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return function (ContainerConfigurator $container) { | ||
$container->extension('configuration', [ | ||
'foo' => 'value1', | ||
'bar' => ['value2', 'value3'], | ||
]); | ||
|
||
$container->services()->set('something', stdClass::class)->public(); | ||
}; |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:configuration="http://example.org/schema/dic/configuration" | ||
xsi:schemaLocation="http://example.org/schema/dic/configuration"> | ||
<configuration:config foo="value1"> | ||
<configuration:bar>value2</configuration:bar> | ||
<configuration:bar>value3</configuration:bar> | ||
</configuration:config> | ||
|
||
<services> | ||
<service id="something" class="\stdClass" public="true" /> | ||
</services> | ||
</container> |
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,8 @@ | ||
configuration: | ||
foo: value1 | ||
bar: [value2, value3] | ||
|
||
services: | ||
something: | ||
class: \stdClass | ||
public: true |
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,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Tests\Functional\Neusta\Pimcore\TestingFramework; | ||
|
||
use Fixtures\ConfigurationBundle\ConfigurationBundle; | ||
use Neusta\Pimcore\TestingFramework\Kernel\TestKernel; | ||
use Neusta\Pimcore\TestingFramework\Test\ConfigurableKernelTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
final class BundleConfigurationTest extends ConfigurableKernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function extension_configuration(): void | ||
{ | ||
self::bootKernel(['config' => function (TestKernel $kernel) { | ||
$kernel->addTestBundle(ConfigurationBundle::class); | ||
$kernel->addTestExtensionConfig('configuration', [ | ||
'foo' => 'value1', | ||
'bar' => ['value2', 'value3'], | ||
]); | ||
}]); | ||
|
||
$container = self::getContainer(); | ||
|
||
$this->assertEquals('value1', $container->getParameter('configuration.foo')); | ||
$this->assertEquals(['value2', 'value3'], $container->getParameter('configuration.bar')); | ||
} | ||
|
||
public function provideDifferentConfigurationFormats(): iterable | ||
{ | ||
yield 'YAML' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.yaml']; | ||
yield 'XML' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.xml']; | ||
yield 'PHP' => [__DIR__ . '/../Fixtures/Resources/ConfigurationBundle/config.php']; | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider provideDifferentConfigurationFormats | ||
*/ | ||
public function different_configuration_formats(string $config): void | ||
{ | ||
self::bootKernel(['config' => function (TestKernel $kernel) use ($config) { | ||
$kernel->addTestBundle(ConfigurationBundle::class); | ||
$kernel->addTestConfig($config); | ||
}]); | ||
|
||
$container = self::getContainer(); | ||
|
||
$this->assertEquals('value1', $container->getParameter('configuration.foo')); | ||
$this->assertEquals(['value2', 'value3'], $container->getParameter('configuration.bar')); | ||
self::assertInstanceOf(\stdClass::class, $container->get('something', ContainerInterface::NULL_ON_INVALID_REFERENCE)); | ||
} | ||
} |
Empty file.
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