|
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,74 @@ 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(array(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 | + $resolver = $this->createControllerResolver(null, $container); |
| 139 | + $request = Request::create('/'); |
| 140 | + $request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action')); |
| 141 | + |
| 142 | + $controller = $resolver->getController($request); |
| 143 | + |
| 144 | + $this->assertSame(array(ImpossibleConstructController::class, 'action'), $controller); |
| 145 | + } |
| 146 | + |
| 147 | + public function testNonCaseMisMatchController() |
| 148 | + { |
| 149 | + $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); |
| 150 | + $container->expects($this->atLeastOnce()) |
| 151 | + ->method('has') |
| 152 | + ->with('Symfony\Component\HttpKernel\Tests\Controller\impossibleconstructcontroller') |
| 153 | + ->will($this->returnValue(false)) |
| 154 | + ; |
| 155 | + |
| 156 | + $container->expects($this->atLeastOnce()) |
| 157 | + ->method('getServiceIds') |
| 158 | + ->with() |
| 159 | + ->will($this->returnValue(array(ImpossibleConstructController::class))) |
| 160 | + ; |
| 161 | + |
| 162 | + if (method_exists($this, 'expectException')) { |
| 163 | + $this->expectException(\InvalidArgumentException::class); |
| 164 | + $this->expectExceptionMessage('Case mismatch detected, did you mean "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController"?'); |
| 165 | + } else { |
| 166 | + $this->setExpectedException(\InvalidArgumentException::class, 'Case mismatch detected, did you mean "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController"?'); |
| 167 | + } |
| 168 | + |
| 169 | + $resolver = $this->createControllerResolver(null, $container); |
| 170 | + $request = Request::create('/'); |
| 171 | + $request->attributes->set('_controller', array('Symfony\Component\HttpKernel\Tests\Controller\impossibleconstructcontroller', 'action')); |
| 172 | + |
| 173 | + $controller = $resolver->getController($request); |
| 174 | + |
| 175 | + $this->assertSame(array(ImpossibleConstructController::class, 'action'), $controller); |
| 176 | + } |
| 177 | + |
109 | 178 | public function testNonInstantiableControllerWithCorrespondingService()
|
110 | 179 | {
|
111 | 180 | $service = new \stdClass();
|
@@ -196,3 +265,14 @@ public static function action()
|
196 | 265 | {
|
197 | 266 | }
|
198 | 267 | }
|
| 268 | + |
| 269 | +class ImpossibleConstructController |
| 270 | +{ |
| 271 | + public function __construct($toto, $controller) |
| 272 | + { |
| 273 | + } |
| 274 | + |
| 275 | + public function action() |
| 276 | + { |
| 277 | + } |
| 278 | +} |
0 commit comments