/
FormPassTest.php
146 lines (117 loc) · 4.7 KB
/
FormPassTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Form\AbstractType;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormPassTest extends \PHPUnit_Framework_TestCase
{
public function testDoNothingIfFormExtensionNotLoaded()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new FormPass());
$container->compile();
$this->assertFalse($container->hasDefinition('form.extension'));
}
public function testAddTaggedTypes()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new FormPass());
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
$extDefinition->setArguments(array(
new Reference('service_container'),
array(),
array(),
array(),
));
$definition1 = new Definition(__CLASS__.'_Type1');
$definition1->addTag('form.type');
$definition2 = new Definition(__CLASS__.'_Type2');
$definition2->addTag('form.type');
$container->setDefinition('form.extension', $extDefinition);
$container->setDefinition('my.type1', $definition1);
$container->setDefinition('my.type2', $definition2);
$container->compile();
$extDefinition = $container->getDefinition('form.extension');
$this->assertEquals(array(
__CLASS__.'_Type1' => 'my.type1',
__CLASS__.'_Type2' => 'my.type2',
), $extDefinition->getArgument(1));
}
public function testAddTaggedTypeExtensions()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new FormPass());
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
$extDefinition->setArguments(array(
new Reference('service_container'),
array(),
array(),
array(),
));
$definition1 = new Definition('stdClass');
$definition1->addTag('form.type_extension', array('alias' => 'type1'));
$definition2 = new Definition('stdClass');
$definition2->addTag('form.type_extension', array('alias' => 'type1'));
$definition3 = new Definition('stdClass');
$definition3->addTag('form.type_extension', array('alias' => 'type2'));
$container->setDefinition('form.extension', $extDefinition);
$container->setDefinition('my.type_extension1', $definition1);
$container->setDefinition('my.type_extension2', $definition2);
$container->setDefinition('my.type_extension3', $definition3);
$container->compile();
$extDefinition = $container->getDefinition('form.extension');
$this->assertSame(array(
'type1' => array(
'my.type_extension1',
'my.type_extension2',
),
'type2' => array(
'my.type_extension3',
),
), $extDefinition->getArgument(2));
}
public function testAddTaggedGuessers()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new FormPass());
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
$extDefinition->setArguments(array(
new Reference('service_container'),
array(),
array(),
array(),
));
$definition1 = new Definition('stdClass');
$definition1->addTag('form.type_guesser');
$definition2 = new Definition('stdClass');
$definition2->addTag('form.type_guesser');
$container->setDefinition('form.extension', $extDefinition);
$container->setDefinition('my.guesser1', $definition1);
$container->setDefinition('my.guesser2', $definition2);
$container->compile();
$extDefinition = $container->getDefinition('form.extension');
$this->assertSame(array(
'my.guesser1',
'my.guesser2',
), $extDefinition->getArgument(3));
}
}
class FormPassTest_Type1 extends AbstractType
{
}
class FormPassTest_Type2 extends AbstractType
{
}