Skip to content

Commit

Permalink
Test bundle & config
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Mar 11, 2024
1 parent c87c5de commit 6ccf82c
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ jobs:
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Add Pimcore Admin UI
run: composer require --dev pimcore/admin-ui-classic-bundle --no-interaction
if: matrix.dependencies == 'highest'

- name: Execute tests
run: composer tests
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Unit\\Neusta\\Pimcore\\TestingFramework\\": "tests/Unit"
"Fixtures\\": "tests/Fixtures/",
"Tests\\Functional\\Neusta\\Pimcore\\TestingFramework\\": "tests/Functional/",
"Tests\\Unit\\Neusta\\Pimcore\\TestingFramework\\": "tests/Unit/"
}
},
"config": {
Expand Down
10 changes: 10 additions & 0 deletions tests/Fixtures/ConfigurationBundle/ConfigurationBundle.php
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
{
}
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;
}
}
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']);
}
}
12 changes: 12 additions & 0 deletions tests/Fixtures/Resources/ConfigurationBundle/config.php
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();
};
14 changes: 14 additions & 0 deletions tests/Fixtures/Resources/ConfigurationBundle/config.xml
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>
8 changes: 8 additions & 0 deletions tests/Fixtures/Resources/ConfigurationBundle/config.yaml
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
57 changes: 57 additions & 0 deletions tests/Functional/BundleConfigurationTest.php
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 added tests/app/config/.gitkeep
Empty file.
11 changes: 9 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

declare(strict_types=1);

use Doctrine\Common\Annotations\AnnotationRegistry;
use Neusta\Pimcore\TestingFramework\Kernel\TestKernel;
use Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore;

include dirname(__DIR__) . '/vendor/autoload.php';

Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
AnnotationRegistry::registerLoader('class_exists');

Neusta\Pimcore\TestingFramework\Pimcore\BootstrapPimcore::bootstrap();
BootstrapPimcore::bootstrap(
PIMCORE_PROJECT_ROOT: __DIR__ . '/app',
KERNEL_CLASS: TestKernel::class,
);

0 comments on commit 6ccf82c

Please sign in to comment.