17 use Prophecy\Argument;
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
40 GeneralUtility::purgeInstances();
49 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
50 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
53 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
54 $responseProphecy = $this->prophesize(ResponseInterface::class);
55 $routerProphecy = $this->prophesize(Router::class);
56 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
57 $routeProphecy = $this->prophesize(Route::class);
58 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
59 $routeProphecy->getOption(
'access')->willReturn(
'public');
60 $routeProphecy->getOption(
'referrer')->willReturn(
false);
61 $routeProphecy->getOption(
'module')->willReturn(
false);
62 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
63 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
66 $routeProphecy->getOption(
'target')->willReturn($target);
67 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
69 $this->expectException(\InvalidArgumentException::class);
70 $this->expectExceptionCode(1425381442);
73 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
81 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
82 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
85 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
86 $responseProphecy = $this->prophesize(ResponseInterface::class);
87 $routerProphecy = $this->prophesize(Router::class);
88 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
89 $routeProphecy = $this->prophesize(Route::class);
90 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
91 $routeProphecy->getOption(
'access')->willReturn(
'public');
92 $routeProphecy->getOption(
'referrer')->willReturn(
false);
93 $routeProphecy->getOption(
'module')->willReturn(
false);
94 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
95 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
97 $target = RouteDispatcherClassFixture::class .
'::mainAction';
98 $routeProphecy->getOption(
'target')->willReturn($target);
99 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
101 $this->expectException(\RuntimeException::class);
102 $this->expectExceptionCode(1520756142);
105 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
113 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
114 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
117 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
118 $responseProphecy = $this->prophesize(ResponseInterface::class);
119 $routerProphecy = $this->prophesize(Router::class);
120 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
121 $routeProphecy = $this->prophesize(Route::class);
122 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
123 $routeProphecy->getOption(
'access')->willReturn(
'public');
124 $routeProphecy->getOption(
'referrer')->willReturn(
false);
125 $routeProphecy->getOption(
'module')->willReturn(
false);
126 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
127 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
129 $target =
static function (ServerRequestInterface $request) {
130 throw new \RuntimeException(
'I have been called. Good!', 1520756466);
132 $routeProphecy->getOption(
'target')->willReturn($target);
133 $requestProphecy->withAttribute(
'target', Argument::type(\Closure::class))->willReturn($requestProphecy->reveal());
135 $this->expectException(\RuntimeException::class);
136 $this->expectExceptionCode(1520756466);
139 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
147 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
148 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
151 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
152 $responseProphecy = $this->prophesize(ResponseInterface::class);
153 $routerProphecy = $this->prophesize(Router::class);
154 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
155 $routeProphecy = $this->prophesize(Route::class);
156 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
157 $routeProphecy->getOption(
'access')->willReturn(
'public');
158 $routeProphecy->getOption(
'referrer')->willReturn(
false);
159 $routeProphecy->getOption(
'module')->willReturn(
false);
160 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
161 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
163 $target = RouteDispatcherClassInvokeFixture::class;
164 $routeProphecy->getOption(
'target')->willReturn($target);
165 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
167 $this->expectException(\RuntimeException::class);
168 $this->expectExceptionCode(1520756623);
171 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
179 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
180 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
183 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
184 $responseProphecy = $this->prophesize(ResponseInterface::class);
185 $routerProphecy = $this->prophesize(Router::class);
186 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
187 $routeProphecy = $this->prophesize(Route::class);
188 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
189 $routeProphecy->getOption(
'access')->willReturn(
'public');
190 $routeProphecy->getOption(
'referrer')->willReturn(
false);
191 $routeProphecy->getOption(
'module')->willReturn(
false);
192 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
193 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
195 $target = RouteDispatcherClassWithoutInvokeFixture::class;
196 $routeProphecy->getOption(
'target')->willReturn($target);
197 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
199 $this->expectException(\InvalidArgumentException::class);
200 $this->expectExceptionCode(1442431631);
203 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
211 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
212 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
215 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
216 $responseProphecy = $this->prophesize(ResponseInterface::class);
217 $routerProphecy = $this->prophesize(Router::class);
218 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
219 $routeProphecy = $this->prophesize(Route::class);
220 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
221 $routeProphecy->getOption(
'access')->willReturn(
'public');
222 $routeProphecy->getOption(
'referrer')->willReturn(
false);
223 $routeProphecy->getOption(
'module')->willReturn(
false);
224 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
225 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
227 $target = RouteDispatcherClassFixture::class .
'::mainAction';
228 $routeProphecy->getOption(
'target')->willReturn($target);
229 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
231 $this->expectException(\RuntimeException::class);
232 $this->expectExceptionCode(1520756142);
235 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
243 $formProtectionProphecy = $this->prophesize(AbstractFormProtection::class);
244 $formProtectionProphecy->validateToken(Argument::cetera())->willReturn(
true);
247 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
248 $responseProphecy = $this->prophesize(ResponseInterface::class);
249 $routerProphecy = $this->prophesize(Router::class);
250 GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
251 $routeProphecy = $this->prophesize(Route::class);
252 $routerProphecy->matchRequest($requestProphecy->reveal())->willReturn($routeProphecy->reveal());
253 $routeProphecy->getOption(
'access')->willReturn(
'public');
254 $routeProphecy->getOption(
'referrer')->willReturn(
false);
255 $routeProphecy->getOption(
'module')->willReturn(
false);
256 $requestProphecy->withAttribute(
'route', $routeProphecy->reveal())->willReturn($requestProphecy->reveal());
257 $requestProphecy->getAttribute(
'route')->willReturn($routeProphecy->reveal());
259 $target = RouteDispatcherStaticClassFixture::class .
'::mainAction';
260 $routeProphecy->getOption(
'target')->willReturn($target);
261 $requestProphecy->withAttribute(
'target', $target)->willReturn($requestProphecy->reveal());
263 $this->expectException(\RuntimeException::class);
264 $this->expectExceptionCode(1520757000);
267 $subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());