Skip to content

Commit d3a7a13

Browse files
committed
Added tests for the ValidationPass
1 parent 149bd39 commit d3a7a13

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
} else {
54+
if ($hasValidator) {
55+
$definition = $this->container->findDefinition('validator.builder');
56+
57+
$this->assertFalse($definition->hasMethodCall('addXmlMappings'));
58+
}
59+
}
60+
}
61+
62+
/**
63+
* Provides the contexts in witch the documents validation registering occurs.
64+
*
65+
* A context is:
66+
*
67+
* `[$hasPhpcr, $hasValidator, $shouldBeRegistered]`
68+
*
69+
* where:
70+
* - _$hasPhpcr: Is the PHPCR backend enabled ?
71+
* - _$hasValidator: Is the validator available ?
72+
* - _$shouldBeRegistered_: Should the documents validation be registered ?
73+
*/
74+
public function provideDocumentsValidationContext()
75+
{
76+
return [
77+
[true, true, true],
78+
[true, false, false],
79+
[false, true, false],
80+
[false, false, false],
81+
];
82+
}
83+
}

0 commit comments

Comments
 (0)