Skip to content

Commit 3439fb2

Browse files
committed
Adding tests
1 parent 389897c commit 3439fb2

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/Infrastructure/Http/Dispatcher/Dispatcher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public function dispatch(
135135
$handler = $this->stringHandler($handler, $request);
136136
}
137137

138+
if ($handler instanceof ResponseInterface) {
139+
return $handler;
140+
}
141+
138142
if ($handler instanceof RequestHandlerInterface) {
139143
return $handler->handle($request);
140144
}

tests/TestCase/Infrastructure/Http/Dispatcher/DispatcherTest.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DispatcherTest extends TestCase
3030
/**
3131
* @return void
3232
*/
33-
public function testDispatching(): void
33+
public function testDispatchingCallableHandler(): void
3434
{
3535
$container = $this->getMockBuilder(ContainerInterface::class)
3636
->getMock();
@@ -46,5 +46,52 @@ public function testDispatching(): void
4646
$dispatcher = new Dispatcher($container);
4747
$result = $dispatcher->dispatch($request, $callable);
4848
$this->assertInstanceOf(ResponseInterface::class, $result);
49+
50+
new class {
51+
public function log($msg)
52+
{
53+
echo $msg;
54+
}
55+
};
56+
}
57+
58+
/**
59+
* @return void
60+
*/
61+
public function testDispatchingClassString(): void
62+
{
63+
$container = $this->getMockBuilder(ContainerInterface::class)
64+
->getMock();
65+
$request = $this->getMockBuilder(ServerRequestInterface::class)
66+
->getMock();
67+
$response = $this->getMockBuilder(ResponseInterface::class)
68+
->getMock();
69+
70+
$class = new class($response) {
71+
protected $response;
72+
public function __construct(ResponseInterface $response)
73+
{
74+
$this->response = $response;
75+
}
76+
77+
public function login(ServerRequestInterface $request)
78+
{
79+
return $this->response;
80+
}
81+
};
82+
83+
$container->expects($this->any())
84+
->method('has')
85+
->with('Users')
86+
->willReturn(true);
87+
88+
$container->expects($this->any())
89+
->method('get')
90+
->with('Users')
91+
->willReturn($class);
92+
93+
$dispatcher = new Dispatcher($container);
94+
$result = $dispatcher->dispatch($request, 'Users@login');
95+
$this->assertInstanceOf(ResponseInterface::class, $result);
4996
}
5097
}

0 commit comments

Comments
 (0)