Skip to content

Commit

Permalink
Replace HTTPbin with Postman Echo
Browse files Browse the repository at this point in the history
  • Loading branch information
jenky committed Jun 21, 2023
1 parent 0e5ee52 commit bdc5740
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tests/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Jenky\Atlas\ConnectorConfigurator;
use Jenky\Atlas\Middleware\Interceptor;
use Jenky\Atlas\Mock\MockClient;
use Jenky\Atlas\Tests\Services\HTTPBin\Connector;
use Jenky\Atlas\Tests\Services\HTTPBin\GetHeadersRequest;
use Jenky\Atlas\NullConnector;
use Jenky\Atlas\Tests\Services\DummyRequest;
use Jenky\Atlas\Tests\Services\PostmanEcho\EchoConnector;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -17,15 +17,16 @@ final class ConnectorTest extends TestCase
{
public function test_middleware(): void
{
$connector = new Connector();

$this->assertCount(1, $connector->middleware());
$connector = new NullConnector();

$connector->middleware()->push(static function (RequestInterface $request, callable $next) {
return $next($request->withHeader('Echo', 'Atlas'));
return $next(
$request->withHeader('Echo', 'Atlas')
->withHeader('X-Foo', 'bar')
);
}, 'echo');

$this->assertCount(2, $connector->middleware());
$this->assertCount(1, $connector->middleware());

$id = uniqid();

Expand All @@ -41,28 +42,28 @@ public function test_middleware(): void
return $next($request);
}, 'first');

$this->assertCount(5, $connector->middleware());
$this->assertCount(4, $connector->middleware());

$middleware = $connector->middleware()->all();

$this->assertSame('first', $middleware[0][1]);
$this->assertSame('echo', $middleware[3][1]);
$this->assertSame('echo', $middleware[2][1]);

$connector->middleware()->remove('first');

$this->assertCount(4, $connector->middleware());
$this->assertCount(3, $connector->middleware());

$connector->middleware()->push(static function (RequestInterface $request, callable $next) {
return $next($request->withHeader('X-Foo', 'bar'));
});

$connector->middleware()->remove('echo');

$response = $connector->send(new GetHeadersRequest());
$response = $connector->send(new DummyRequest('https://postman-echo.com/headers'));

$this->assertTrue($response->successful());
$this->assertSame('bar', $response->data()['headers']['X-Foo'] ?? null);
$this->assertSame($id, $response->data()['headers']['X-Unique-Id'] ?? null);
$this->assertSame('bar', $response->data()['headers']['x-foo'] ?? null);
$this->assertSame($id, $response->data()['headers']['x-unique-id'] ?? null);
$this->assertSame($id, $response->header('X-Unique-Id'));
$this->assertArrayNotHasKey('Echo', $response->data()['headers'] ?? []);
}
Expand Down

0 comments on commit bdc5740

Please sign in to comment.