Skip to content

Commit cad04a9

Browse files
committed
Make sure MockMiddleware matches current standards
1 parent 50afc5f commit cad04a9

File tree

4 files changed

+14
-52
lines changed

4 files changed

+14
-52
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"require": {
1212
"php": "^7.2",
1313
"api-clients/middleware": "^4.0",
14-
"api-clients/psr7-http-status-exceptions": "^1.0",
1514
"api-clients/transport": "^3.1",
1615
"psr/http-message": "^1.0",
1716
"ringcentral/psr7": "^1.2"

composer.lock

Lines changed: 2 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MockMiddleware.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
use ApiClients\Foundation\Middleware\ErrorTrait;
66
use ApiClients\Foundation\Middleware\MiddlewareInterface;
77
use ApiClients\Foundation\Middleware\PostTrait;
8-
use ApiClients\Tools\Psr7\HttpStatusExceptions\InternalServerErrorException;
98
use Psr\Http\Message\RequestInterface;
109
use React\Promise\CancellablePromiseInterface;
1110
use function React\Promise\reject;
12-
use function React\Promise\resolve;
1311
use RingCentral\Psr7\Response;
1412

1513
final class MockMiddleware implements MiddlewareInterface

tests/MockMiddlewareTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use ApiClients\Middleware\Mock\MockMiddleware;
66
use ApiClients\Middleware\Mock\PathMock;
7-
use ApiClients\Tools\Psr7\HttpStatusExceptions\InternalServerErrorException;
87
use ApiClients\Tools\TestUtilities\TestCase;
98
use function Clue\React\Block\await;
9+
use Psr\Http\Message\ResponseInterface;
1010
use React\EventLoop\Factory;
11+
use function React\Promise\resolve;
1112
use RingCentral\Psr7\Request;
1213
use RingCentral\Psr7\Response;
1314

@@ -18,13 +19,15 @@ class MockMiddlewareTest extends TestCase
1819
{
1920
public function testNoMatchingMock(): void
2021
{
21-
self::expectException(InternalServerErrorException::class);
22-
self::expectExceptionCode(500);
23-
2422
$middleware = new MockMiddleware();
2523
$request = new Request('GET', 'https://example.com', [], '');
2624

27-
await($middleware->pre($request, 'abc'), Factory::create());
25+
/** @var ResponseInterface $response */
26+
$response = await($middleware->pre($request, 'abc')->otherwise(function (ResponseInterface $response) {
27+
return resolve($response);
28+
}), Factory::create());
29+
30+
self::assertSame(500, $response->getStatusCode());
2831
}
2932

3033
public function testMatchingMock(): void
@@ -42,7 +45,10 @@ public function testMatchingMock(): void
4245
);
4346
$request = new Request('GET', 'https://example.com', [], '');
4447

45-
$modifiedRequest = await($middleware->pre($request, 'abc'), Factory::create());
48+
$modifiedRequest = await($middleware->pre($request, 'abc')->otherwise(function (ResponseInterface $response) {
49+
return resolve($response);
50+
}), Factory::create());
51+
4652
self::assertSame(
4753
[
4854
'Foo' => ['Bar'],

0 commit comments

Comments
 (0)