forked from reactphp/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiddlewareRunnerTest.php
More file actions
91 lines (83 loc) · 2.59 KB
/
Copy pathMiddlewareRunnerTest.php
File metadata and controls
91 lines (83 loc) · 2.59 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace React\Tests\Http;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\MiddlewareRunner;
use React\Http\ServerRequest;
use React\Tests\Http\Middleware\ProcessStack;
use RingCentral\Psr7\Response;
use Clue\React\Block;
final class MiddlewareRunnerTest extends TestCase
{
public function testDefaultResponse()
{
$this->setExpectedException('\RuntimeException');
$request = new ServerRequest('GET', 'https://example.com/');
$middlewares = array();
$middlewareStack = new MiddlewareRunner($middlewares);
Block\await($middlewareStack($request), Factory::create());
}
public function provideProcessStackMiddlewares()
{
$processStackA = new ProcessStack();
$processStackB = new ProcessStack();
$processStackC = new ProcessStack();
$processStackD = new ProcessStack();
$responseMiddleware = function () {
return new Response(200);
};
return array(
array(
array(
$processStackA,
$responseMiddleware,
),
1,
),
array(
array(
$processStackB,
$processStackB,
$responseMiddleware,
),
2,
),
array(
array(
$processStackC,
$processStackC,
$processStackC,
$responseMiddleware,
),
3,
),
array(
array(
$processStackD,
$processStackD,
$processStackD,
$processStackD,
$responseMiddleware,
),
4,
),
);
}
/**
* @dataProvider provideProcessStackMiddlewares
*/
public function testProcessStack(array $middlewares, $expectedCallCount)
{
$request = new ServerRequest('GET', 'https://example.com/');
$middlewareStack = new MiddlewareRunner($middlewares);
/** @var ResponseInterface $result */
$result = Block\await($middlewareStack($request), Factory::create());
$this->assertSame(200, $result->getStatusCode());
foreach ($middlewares as $middleware) {
if (!($middleware instanceof ProcessStack)) {
continue;
}
$this->assertSame($expectedCallCount, $middleware->getCallCount());
}
}
}