|
13 | 13 |
|
14 | 14 | use Psr\Container\ContainerInterface;
|
15 | 15 | use Psr\Log\LoggerInterface;
|
| 16 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
16 | 17 | use Symfony\Component\HttpFoundation\Request;
|
17 | 18 | use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
18 | 19 |
|
@@ -106,6 +107,44 @@ public function testNonInstantiableController()
|
106 | 107 | $this->assertSame(array(NonInstantiableController::class, 'action'), $controller);
|
107 | 108 | }
|
108 | 109 |
|
| 110 | + public function testNonConstructController() |
| 111 | + { |
| 112 | + $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); |
| 113 | + $container->expects($this->at(0)) |
| 114 | + ->method('has') |
| 115 | + ->with(ImpossibleConstructController::class) |
| 116 | + ->will($this->returnValue(true)) |
| 117 | + ; |
| 118 | + |
| 119 | + $container->expects($this->at(1)) |
| 120 | + ->method('has') |
| 121 | + ->with(ImpossibleConstructController::class) |
| 122 | + ->will($this->returnValue(false)) |
| 123 | + ; |
| 124 | + |
| 125 | + $container->expects($this->atLeastOnce()) |
| 126 | + ->method('getRemovedIds') |
| 127 | + ->with() |
| 128 | + ->will($this->returnValue([ImpossibleConstructController::class])) |
| 129 | + ; |
| 130 | + |
| 131 | + if (method_exists($this, 'expectException')) { |
| 132 | + $this->expectException(\InvalidArgumentException::class); |
| 133 | + $this->expectExceptionMessage('The controller Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController seems to be removed from the container, which means that he maybe private, add the tag \'controller.service_arguments\' or made it public.'); |
| 134 | + } else { |
| 135 | + $this->setExpectedException(\InvalidArgumentException::class, 'The controller Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController seems to be removed from the container, which means that he maybe private, add the tag \'controller.service_arguments\' or made it public.'); |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + $resolver = $this->createControllerResolver(null, $container); |
| 140 | + $request = Request::create('/'); |
| 141 | + $request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action')); |
| 142 | + |
| 143 | + $controller = $resolver->getController($request); |
| 144 | + |
| 145 | + $this->assertSame(array(ImpossibleConstructController::class, 'action'), $controller); |
| 146 | + } |
| 147 | + |
109 | 148 | public function testNonInstantiableControllerWithCorrespondingService()
|
110 | 149 | {
|
111 | 150 | $service = new \stdClass();
|
@@ -196,3 +235,14 @@ public static function action()
|
196 | 235 | {
|
197 | 236 | }
|
198 | 237 | }
|
| 238 | + |
| 239 | +class ImpossibleConstructController |
| 240 | +{ |
| 241 | + public function __construct(string $toto, $controller) |
| 242 | + { |
| 243 | + } |
| 244 | + |
| 245 | + public function action() |
| 246 | + { |
| 247 | + } |
| 248 | +} |
0 commit comments