-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…compiler-passes- EZP-28722: Add unit tests to Compiler Passes
- Loading branch information
Showing
9 changed files
with
272 additions
and
6 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
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
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
69 changes: 69 additions & 0 deletions
69
src/bundle/Tests/DependencyInjection/Compiler/ComponentPassTest.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,69 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use EzSystems\EzPlatformAdminUi\Component\Registry; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException; | ||
|
||
class ComponentPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setDefinition(Registry::class, new Definition()); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container->addCompilerPass(new ComponentPass()); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$taggedServiceId = 'collected_service'; | ||
$collectedService = new Definition(); | ||
$collectedService->addTag(ComponentPass::TAG_NAME, ['group' => 'someGroup']); | ||
$this->setDefinition($taggedServiceId, $collectedService); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag( | ||
$taggedServiceId, | ||
ComponentPass::TAG_NAME, | ||
['group' => 'someGroup'] | ||
); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( | ||
Registry::class, | ||
'addComponent', | ||
['someGroup', $taggedServiceId, new Reference($taggedServiceId)] | ||
); | ||
} | ||
|
||
public function testProcessWithNoGroup() | ||
{ | ||
$taggedServiceId = 'collected_service'; | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage(sprintf('Argument \'%s\' is invalid: Tag %s must contain "group" argument.', $taggedServiceId, ComponentPass::TAG_NAME)); | ||
|
||
$collectedService = new Definition(); | ||
$collectedService->addTag(ComponentPass::TAG_NAME); | ||
$this->setDefinition($taggedServiceId, $collectedService); | ||
|
||
$this->compile(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/bundle/Tests/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.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,45 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler; | ||
|
||
use EzSystems\EzPlatformAdminUi\Tab\TabGroup; | ||
use EzSystems\EzPlatformAdminUi\Tab\TabRegistry; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class SystemInfoTabGroupPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setDefinition(TabRegistry::class, new Definition()); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container->addCompilerPass(new SystemInfoTabGroupPass()); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$tabGroupDefinition = new Definition(TabGroup::class, ['systeminfo']); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( | ||
TabRegistry::class, | ||
'addTabGroup', | ||
[$tabGroupDefinition] | ||
); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/bundle/Tests/DependencyInjection/Compiler/TabPassTest.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,54 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler; | ||
|
||
use EzSystems\EzPlatformAdminUi\Tab\TabRegistry; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class TabPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setDefinition(TabRegistry::class, new Definition()); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container->addCompilerPass(new TabPass()); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$taggedServiceId = 'collected_service'; | ||
$collectedService = new Definition(); | ||
$collectedService->addTag(TabPass::TAG_TAB, ['group' => 'someGroup']); | ||
$this->setDefinition($taggedServiceId, $collectedService); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag( | ||
$taggedServiceId, | ||
TabPass::TAG_TAB, | ||
['group' => 'someGroup'] | ||
); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( | ||
TabRegistry::class, | ||
'addTab', | ||
[new Reference($taggedServiceId), 'someGroup'] | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/bundle/Tests/DependencyInjection/Compiler/UiConfigProviderPassTest.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,70 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler; | ||
|
||
use EzSystems\EzPlatformAdminUi\UI\Config\Aggregator; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class UiConfigProviderPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->setDefinition(Aggregator::class, new Definition()); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container->addCompilerPass(new UiConfigProviderPass()); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$taggedServiceId = 'collected_service'; | ||
$collectedService = new Definition(); | ||
$collectedService->addTag(UiConfigProviderPass::TAG_CONFIG_PROVIDER, ['key' => 'someKey']); | ||
$this->setDefinition($taggedServiceId, $collectedService); | ||
|
||
$taggedServiceWithoutKeyId = 'collected_service_without_key'; | ||
$collectedServiceWithoutKey = new Definition(); | ||
$collectedServiceWithoutKey->addTag(UiConfigProviderPass::TAG_CONFIG_PROVIDER); | ||
$this->setDefinition($taggedServiceWithoutKeyId, $collectedServiceWithoutKey); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag( | ||
$taggedServiceId, | ||
UiConfigProviderPass::TAG_CONFIG_PROVIDER, | ||
['key' => 'someKey'] | ||
); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag( | ||
$taggedServiceWithoutKeyId, | ||
UiConfigProviderPass::TAG_CONFIG_PROVIDER | ||
); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( | ||
Aggregator::class, | ||
'addProvider', | ||
['someKey', new Reference($taggedServiceId)] | ||
); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( | ||
Aggregator::class, | ||
'addProvider', | ||
[$taggedServiceWithoutKeyId, new Reference($taggedServiceWithoutKeyId)] | ||
); | ||
} | ||
} |