|
31 | 31 | use Hyperf\Translation\Translator;
|
32 | 32 | use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
33 | 33 | use Hyperf\Validation\Middleware\ValidationMiddleware;
|
| 34 | +use Hyperf\Validation\ValidationException; |
34 | 35 | use Hyperf\Validation\ValidatorFactory;
|
35 | 36 | use HyperfTest\Validation\Cases\Stub\DemoController;
|
36 | 37 | use HyperfTest\Validation\Cases\Stub\DemoRequest;
|
@@ -169,4 +170,27 @@ public function createContainer()
|
169 | 170 |
|
170 | 171 | return $container;
|
171 | 172 | }
|
| 173 | + |
| 174 | + public function testValidationOfInvocableControllerRoutingRequests() |
| 175 | + { |
| 176 | + $this->expectException(ValidationException::class); |
| 177 | + |
| 178 | + $container = $this->createContainer(); |
| 179 | + $factory = $container->get(DispatcherFactory::class); |
| 180 | + |
| 181 | + $router = $factory->getRouter('http'); |
| 182 | + $router->addRoute('POST', '/invokable', 'HyperfTest\Validation\Cases\Stub\DemoController'); |
| 183 | + |
| 184 | + $dispatcher = $factory->getDispatcher('http'); |
| 185 | + $middleware = new ValidationMiddleware($container); |
| 186 | + $coreMiddleware = new CoreMiddleware($container, 'http'); |
| 187 | + $handler = new HttpRequestHandler([$middleware], $coreMiddleware, $container); |
| 188 | + Context::set(ResponseInterface::class, new Response()); |
| 189 | + |
| 190 | + $request = (new Request('POST', new Uri('/invokable'))) |
| 191 | + ->withParsedBody(['username' => 'Hyperf']); |
| 192 | + $routes = $dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath()); |
| 193 | + $request = Context::set(ServerRequestInterface::class, $request->withAttribute(Dispatched::class, new Dispatched($routes))); |
| 194 | + $middleware->process($request, $handler); |
| 195 | + } |
172 | 196 | }
|
0 commit comments