Skip to content

Commit

Permalink
Merge 55b0d4d into 422c988
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Mar 18, 2019
2 parents 422c988 + 55b0d4d commit 513f4ea
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @deprecated This class is deprecated in KunstmaanConfigBundle 5.3 and will be removed in KunstmaanConfigBundle 6.0. The entity validation is moved to the bundle configuration instead.
*/
class KunstmaanConfigConfigurationPass implements CompilerPassInterface
{
/**
Expand Down
20 changes: 19 additions & 1 deletion src/Kunstmaan/ConfigBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Kunstmaan\ConfigBundle\Entity\ConfigurationInterface as KunstmaanConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
Expand All @@ -28,10 +29,27 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->arrayNode('entities')
->defaultValue(array())
->defaultValue([])
->normalizeKeys(false)
->info('The list of entities to manage in the settings zone')
->prototype('scalar')->end()
->beforeNormalization()
->always()
->then(function ($entities) {
foreach ($entities as $entity) {
if (!class_exists($entity)) {
throw new \InvalidArgumentException(sprintf('Entity "%s" does not exist', $entity));
}

// Check if entity implements the ConfigurationInterface.
if (!in_array(KunstmaanConfigurationInterface::class, class_implements($entity))) {
throw new \RuntimeException(sprintf('The entity class "%s" needs to implement the %s', $entity, KunstmaanConfigurationInterface::class));
}
}

return $entities;
})
->end()
->end()
->end();

Expand Down
1 change: 0 additions & 1 deletion src/Kunstmaan/ConfigBundle/KunstmaanConfigBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class KunstmaanConfigBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new KunstmaanConfigConfigurationPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new DeprecateClassParametersPass());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kunstmaan\ConfigBundle\Tests\DependencyInjection;

use Kunstmaan\ConfigBundle\DependencyInjection\Configuration;
use Kunstmaan\ConfigBundle\Entity\ConfigurationInterface;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -34,4 +35,72 @@ public function testConfigDoesntGenerateAsExpected()
{
$this->assertPartialConfigurationIsInvalid([['fail']], 'entities');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Entity "App\UndefinedEntity" does not exist
*/
public function testConfigUndefinedEntity()
{
$array = [
'entities' => [
'App\\UndefinedEntity',
],
];

$this->assertProcessedConfigurationEquals([$array], $array);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The entity class "Kunstmaan\ConfigBundle\Tests\DependencyInjection\InvalidConfigEntity" needs to implement the Kunstmaan\ConfigBundle\Entity\ConfigurationInterface
*/
public function testConfigInvalidEntity()
{
$array = [
'entities' => [
InvalidConfigEntity::class,
],
];

$this->assertProcessedConfigurationEquals([$array], $array);
}

public function testConfigValidEntity()
{
$array = [
'entities' => [
ValidConfigEntity::class,
],
];

$this->assertProcessedConfigurationEquals([$array], $array);
}
}

class ValidConfigEntity implements ConfigurationInterface
{
public function getDefaultAdminType()
{
return 'whatever';
}

public function getInternalName()
{
return 'whatever';
}

public function getLabel()
{
return 'whatever';
}

public function getRoles()
{
return [];
}
}

class InvalidConfigEntity
{
}

0 comments on commit 513f4ea

Please sign in to comment.