Skip to content

Commit 958a1e8

Browse files
clueWyriHaximus
authored andcommitted
Merge pull request #243 from gabriel-caruso/phpunit
Forward compatibility with PHPUnit 6
2 parents d0d93de + 0b3e251 commit 958a1e8

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
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.10||^5.0",
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: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
use Psr\Http\Message\ServerRequestInterface;
77
use React\EventLoop\Factory;
88
use React\Http\MiddlewareRunner;
9+
use React\Http\Response;
910
use React\Http\ServerRequest;
1011
use React\Tests\Http\Middleware\ProcessStack;
11-
use RingCentral\Psr7\Response;
1212
use Clue\React\Block;
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('bingo');
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(

tests/TestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace React\Tests\Http;
44

5-
class TestCase extends \PHPUnit_Framework_TestCase
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
class TestCase extends BaseTestCase
68
{
79
protected function expectCallableExactly($amount)
810
{

0 commit comments

Comments
 (0)