|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace JMS\SerializerBundle\Tests\DependencyInjection; |
|
20
|
|
|
|
|
21
|
|
|
use JMS\SerializerBundle\DependencyInjection\Compiler\FormErrorHandlerTranslationDomainPass; |
|
22
|
|
|
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
24
|
|
|
use PHPUnit\Framework\TestCase; |
|
25
|
|
|
|
|
26
|
|
|
class FormErrorHandlerTranslationDomainPassTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @param array $configs |
|
30
|
|
|
* |
|
31
|
|
|
* @return ContainerBuilder |
|
32
|
|
|
*/ |
|
33
|
|
|
private function getContainer(array $configs = array()) |
|
34
|
|
|
{ |
|
35
|
|
|
$loader = new JMSSerializerExtension(); |
|
36
|
|
|
$container = new ContainerBuilder(); |
|
37
|
|
|
|
|
38
|
|
|
$container->setParameter('kernel.debug', true); |
|
39
|
|
|
$container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer'); |
|
40
|
|
|
$container->setParameter('kernel.bundles', array()); |
|
41
|
|
|
|
|
42
|
|
|
$loader->load(['jms_serializer' => $configs], $container); |
|
43
|
|
|
|
|
44
|
|
|
return $container; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testExistentParameter() |
|
48
|
|
|
{ |
|
49
|
|
|
$container = $this->getContainer(); |
|
50
|
|
|
$container->setParameter('validator.translation_domain', 'custom_domain'); |
|
51
|
|
|
|
|
52
|
|
|
$pass = new FormErrorHandlerTranslationDomainPass(); |
|
53
|
|
|
$pass->process($container); |
|
54
|
|
|
|
|
55
|
|
|
$args = $container->findDefinition('jms_serializer.form_error_handler')->getArguments(); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertArrayHasKey(1, $args); |
|
58
|
|
|
$this->assertContains('%validator.translation_domain%', $args[1]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testNonExistentParameter() |
|
62
|
|
|
{ |
|
63
|
|
|
$container = $this->getContainer(); |
|
64
|
|
|
|
|
65
|
|
|
$pass = new FormErrorHandlerTranslationDomainPass(); |
|
66
|
|
|
$pass->process($container); |
|
67
|
|
|
|
|
68
|
|
|
$args = $container->findDefinition('jms_serializer.form_error_handler')->getArguments(); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertArrayNotHasKey(1, $args); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|