/
DispatcherTest.php
44 lines (35 loc) · 1.16 KB
/
DispatcherTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Middlewares\Tests;
use Middlewares\Utils\CallableMiddleware;
use Middlewares\Utils\Dispatcher;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
class DispatcherTest extends TestCase
{
public function testDispatcher()
{
$response = Dispatcher::run([
function ($request, $handler) {
$response = $handler->handle($request);
$response->getBody()->write('3');
return $response;
},
function ($request, $handler) {
$response = $handler->handle($request);
$response->getBody()->write('2');
return $response;
},
new CallableMiddleware(function ($request, $handler) {
echo '1';
return $handler->handle($request);
}),
]);
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('123', (string) $response->getBody());
}
public function testMiddlewareException()
{
$this->expectException('UnexpectedValueException');
$response = Dispatcher::run(['']);
}
}