Skip to content

Commit fde33f7

Browse files
carusogabrielWyriHaximus
authored andcommitted
Support PHPUnit 6
1 parent 86f6089 commit fde33f7

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.8.35 || ^5.7",
22-
"clue/block-react": "^1.1"
21+
"clue/block-react": "^1.1",
22+
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
2323
}
2424
}

tests/MiddlewareRunnerTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
final class MiddlewareRunnerTest extends TestCase
1515
{
16+
/**
17+
* @expectedException RuntimeException
18+
* @expectedExceptionMessage No middleware to run
19+
*/
1620
public function testDefaultResponse()
1721
{
18-
$this->setExpectedException('\RuntimeException');
1922
$request = new ServerRequest('GET', 'https://example.com/');
2023
$middlewares = array();
2124
$middlewareStack = new MiddlewareRunner($middlewares);
@@ -90,6 +93,42 @@ public function testProcessStack(array $middlewares, $expectedCallCount)
9093
}
9194
}
9295

96+
public function testNextCanBeRunMoreThanOnceWithoutCorruptingTheMiddlewareStack()
97+
{
98+
$exception = new \RuntimeException('exception');
99+
$retryCalled = 0;
100+
$error = null;
101+
$retry = function ($request, $next) use (&$error, &$retryCalled) {
102+
return $next($request)->then(null, function ($et) use (&$error, $request, $next, &$retryCalled) {
103+
$retryCalled++;
104+
$error = $et;
105+
// the $next failed. discard $error and retry once again:
106+
return $next($request);
107+
});
108+
};
109+
110+
$response = new Response();
111+
$called = 0;
112+
$runner = new MiddlewareRunner(array(
113+
$retry,
114+
function () use (&$called, $response, $exception) {
115+
$called++;
116+
if ($called === 1) {
117+
throw $exception;
118+
}
119+
120+
return $response;
121+
}
122+
));
123+
124+
$request = new ServerRequest('GET', 'https://example.com/');
125+
126+
$this->assertSame($response, Block\await($runner($request), Factory::create()));
127+
$this->assertSame(1, $retryCalled);
128+
$this->assertSame(2, $called);
129+
$this->assertSame($exception, $error);
130+
}
131+
93132
public function testMultipleRunsInvokeAllMiddlewareInCorrectOrder()
94133
{
95134
$requests = array(

0 commit comments

Comments
 (0)