@@ -117,6 +117,56 @@ public function testTypeCollision()
117
117
$ pass ->process ($ container );
118
118
}
119
119
120
+ /**
121
+ * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
122
+ * @expectedExceptionMessage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" for the service "a".
123
+ */
124
+ public function testTypeNotGuessable ()
125
+ {
126
+ $ container = new ContainerBuilder ();
127
+
128
+ $ container ->register ('a1 ' , __NAMESPACE__ .'\Foo ' );
129
+ $ container ->register ('a2 ' , __NAMESPACE__ .'\Foo ' );
130
+ $ aDefinition = $ container ->register ('a ' , __NAMESPACE__ .'\NotGuessableArgument ' );
131
+ $ aDefinition ->setAutowired (true );
132
+
133
+ $ pass = new AutowirePass ();
134
+ $ pass ->process ($ container );
135
+ }
136
+
137
+ /**
138
+ * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
139
+ * @expectedExceptionMessage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\A" for the service "a".
140
+ */
141
+ public function testTypeNotGuessableWithSubclass ()
142
+ {
143
+ $ container = new ContainerBuilder ();
144
+
145
+ $ container ->register ('a1 ' , __NAMESPACE__ .'\B ' );
146
+ $ container ->register ('a2 ' , __NAMESPACE__ .'\B ' );
147
+ $ aDefinition = $ container ->register ('a ' , __NAMESPACE__ .'\NotGuessableArgumentForSubclass ' );
148
+ $ aDefinition ->setAutowired (true );
149
+
150
+ $ pass = new AutowirePass ();
151
+ $ pass ->process ($ container );
152
+ }
153
+
154
+ public function testTypeNotGuessableWithTypeSet ()
155
+ {
156
+ $ container = new ContainerBuilder ();
157
+
158
+ $ container ->register ('a1 ' , __NAMESPACE__ .'\Foo ' );
159
+ $ container ->register ('a2 ' , __NAMESPACE__ .'\Foo ' )->addAutowiringType (__NAMESPACE__ .'\Foo ' );
160
+ $ aDefinition = $ container ->register ('a ' , __NAMESPACE__ .'\NotGuessableArgument ' );
161
+ $ aDefinition ->setAutowired (true );
162
+
163
+ $ pass = new AutowirePass ();
164
+ $ pass ->process ($ container );
165
+
166
+ $ this ->assertCount (1 , $ container ->getDefinition ('a ' )->getArguments ());
167
+ $ this ->assertEquals ('a2 ' , (string ) $ container ->getDefinition ('a ' )->getArgument (0 ));
168
+ }
169
+
120
170
public function testWithTypeSet ()
121
171
{
122
172
$ container = new ContainerBuilder ();
@@ -335,3 +385,15 @@ public function __construct(Dunglas $k, NotARealClass $r)
335
385
{
336
386
}
337
387
}
388
+ class NotGuessableArgument
389
+ {
390
+ public function __construct (Foo $ k )
391
+ {
392
+ }
393
+ }
394
+ class NotGuessableArgumentForSubclass
395
+ {
396
+ public function __construct (A $ k )
397
+ {
398
+ }
399
+ }
0 commit comments