Skip to content

Commit dddf185

Browse files
committed
Merge remote-tracking branch 'origin/2.0'
2 parents 149bd39 + 4ceabf4 commit dddf185

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2017 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\DependencyInjection\Compiler;
13+
14+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
15+
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\TemplatingValidatorPass;
16+
use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaultsTemplatingValidator;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Reference;
19+
20+
class TemplatingValidatorPassTest extends AbstractCompilerPassTestCase
21+
{
22+
public function setUp()
23+
{
24+
parent::setUp();
25+
26+
$this->registerValidatorService();
27+
}
28+
29+
protected function registerCompilerPass(ContainerBuilder $container)
30+
{
31+
$container->addCompilerPass(new TemplatingValidatorPass());
32+
}
33+
34+
/**
35+
* It should replace the validator class with the templating one and
36+
* provide the _templating_ service as second argument.
37+
*/
38+
public function testReplacesValidator()
39+
{
40+
$this->registerService('templating', \stdClass::class);
41+
42+
$this->compile();
43+
44+
$definition = $this->container->getDefinition('cmf_routing.validator.route_defaults');
45+
46+
$this->assertEquals(RouteDefaultsTemplatingValidator::class, $definition->getClass());
47+
$this->assertEquals(['foo', new Reference('templating')], $definition->getArguments());
48+
}
49+
50+
/**
51+
* It should leave the validator untouched when the _templating_ service
52+
* is not available.
53+
*/
54+
public function testDoesNotReplaceValidator()
55+
{
56+
$this->compile();
57+
58+
$definition = $this->container->getDefinition('cmf_routing.validator.route_defaults');
59+
60+
$this->assertEquals(\stdClass::class, $definition->getClass());
61+
$this->assertEquals(['foo', 'bar'], $definition->getArguments());
62+
}
63+
64+
private function registerValidatorService()
65+
{
66+
$definition = $this->registerService('cmf_routing.validator.route_defaults', \stdClass::class);
67+
68+
$definition->setArguments(['foo', 'bar']);
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2017 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\DependencyInjection\Compiler;
13+
14+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
15+
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\ValidationPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
18+
class ValidationPassTest extends AbstractCompilerPassTestCase
19+
{
20+
protected function registerCompilerPass(ContainerBuilder $container)
21+
{
22+
$container->addCompilerPass(new ValidationPass());
23+
}
24+
25+
/**
26+
* It should register the PHPCR documents for validation only when:
27+
* - the PHP backend is enabled AND
28+
* - the validator service is available.
29+
*
30+
* @dataProvider provideDocumentsValidationContext
31+
*/
32+
public function testRegisterDocumentsValidation($hasPhpcr, $hasValidator, $shouldBeRegistered)
33+
{
34+
if ($hasPhpcr) {
35+
$this->setParameter('cmf_routing.backend_type_phpcr', null);
36+
}
37+
38+
if ($hasValidator) {
39+
$this->registerService('validator.builder', \stdClass::class);
40+
}
41+
42+
$this->compile();
43+
44+
if ($shouldBeRegistered) {
45+
$r = new \ReflectionClass(ValidationPass::class);
46+
$dir = \dirname($r->getFilename());
47+
48+
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
49+
'validator.builder',
50+
'addXmlMappings',
51+
[["{$dir}/../../Resources/config/validation-phpcr.xml"]]
52+
);
53+
} elseif ($hasValidator) {
54+
$definition = $this->container->findDefinition('validator.builder');
55+
56+
$this->assertFalse($definition->hasMethodCall('addXmlMappings'));
57+
}
58+
}
59+
60+
/**
61+
* Provides the contexts in witch the documents validation registering occurs.
62+
*
63+
* A context is:
64+
*
65+
* `[$hasPhpcr, $hasValidator, $shouldBeRegistered]`
66+
*
67+
* where:
68+
* - _$hasPhpcr: Is the PHPCR backend enabled ?
69+
* - _$hasValidator: Is the validator available ?
70+
* - _$shouldBeRegistered_: Should the documents validation be registered ?
71+
*/
72+
public function provideDocumentsValidationContext()
73+
{
74+
return [
75+
[true, true, true],
76+
[true, false, false],
77+
[false, true, false],
78+
[false, false, false],
79+
];
80+
}
81+
}

0 commit comments

Comments
 (0)