-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(http): covers http client/server request/response. (#170)
- Loading branch information
Showing
14 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/Unit/Instrumentation/Http/Client/Psr18/RequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZipkinTests\Unit\Instrumentation\Http\Client\Psr18; | ||
|
||
use Zipkin\Instrumentation\Http\Client\Psr18\Request; | ||
use PHPUnit\Framework\TestCase; | ||
use GuzzleHttp\Psr7\Request as Psr7Request; | ||
|
||
final class RequestTest extends TestCase | ||
{ | ||
public function testRequestIsCreatedSuccessfully() | ||
{ | ||
$delegateRequest = new Psr7Request('GET', 'http://test.com/path', ['test_key' => 'test_value']); | ||
$request = new Request($delegateRequest); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/path', $request->getPath()); | ||
$this->assertNull($request->getHeader('test_missing_key')); | ||
$this->assertEquals('test_value', $request->getHeader('test_key')); | ||
$this->assertSame($delegateRequest, $request->unwrap()); | ||
} | ||
|
||
/** | ||
* @dataProvider emptyPaths | ||
*/ | ||
public function testRequestIsNormalizesEmptyPath(string $path) | ||
{ | ||
$delegateRequest = new Psr7Request('GET', $path, ['test_key' => 'test_value']); | ||
$request = new Request($delegateRequest); | ||
$this->assertEquals('/', $request->getPath()); | ||
} | ||
|
||
public function emptyPaths(): array | ||
{ | ||
return [ | ||
['http://test.com'], | ||
['http://test.com/'], | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/Unit/Instrumentation/Http/Client/Psr18/ResponseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZipkinTests\Unit\Instrumentation\Http\Client\Psr18; | ||
|
||
use Zipkin\Instrumentation\Http\Client\Psr18\Response as Psr18Response; | ||
use Zipkin\Instrumentation\Http\Client\Psr18\Request; | ||
use PHPUnit\Framework\TestCase; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Request as Psr7Request; | ||
|
||
final class ResponseTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider delegateRequests | ||
*/ | ||
public function testResponseIsCreatedSuccessfully($request) | ||
{ | ||
$delegateResponse = new Response(202); | ||
$response = new Psr18Response($delegateResponse, $request); | ||
$this->assertEquals(202, $response->getStatusCode()); | ||
$this->assertSame($request, $response->getRequest()); | ||
$this->assertSame($delegateResponse, $response->unwrap()); | ||
} | ||
|
||
public function delegateRequests(): array | ||
{ | ||
return [ | ||
[null], | ||
[new Request(new Psr7Request('GET', 'http://test.com/path'))], | ||
]; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/Unit/Instrumentation/Http/Server/Psr15/RequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZipkinTests\Unit\Instrumentation\Http\Server\Psr15; | ||
|
||
use Zipkin\Instrumentation\Http\Server\Psr15\Request; | ||
use PHPUnit\Framework\TestCase; | ||
use GuzzleHttp\Psr7\Request as Psr7Request; | ||
|
||
final class RequestTest extends TestCase | ||
{ | ||
public function testRequestIsCreatedSuccessfully() | ||
{ | ||
$delegateRequest = new Psr7Request('GET', 'http://test.com/path', ['test_key' => 'test_value']); | ||
$request = new Request($delegateRequest); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/path', $request->getPath()); | ||
$this->assertNull($request->getHeader('test_missing_key')); | ||
$this->assertEquals('test_value', $request->getHeader('test_key')); | ||
$this->assertSame($delegateRequest, $request->unwrap()); | ||
} | ||
|
||
/** | ||
* @dataProvider emptyPaths | ||
*/ | ||
public function testRequestIsNormalizesEmptyPath(string $path) | ||
{ | ||
$delegateRequest = new Psr7Request('GET', 'http://test.com', ['test_key' => 'test_value']); | ||
$request = new Request($delegateRequest); | ||
$this->assertEquals('/', $request->getPath()); | ||
} | ||
|
||
public function emptyPaths(): array | ||
{ | ||
return [ | ||
['http://test.com'], | ||
['http://test.com/'], | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/Unit/Instrumentation/Http/Server/Psr15/ResponseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZipkinTests\Unit\Instrumentation\Http\Server\Psr15; | ||
|
||
use Zipkin\Instrumentation\Http\Server\Psr15\Response as Psr15Response; | ||
use Zipkin\Instrumentation\Http\Server\Psr15\Request; | ||
use PHPUnit\Framework\TestCase; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Request as Psr7Request; | ||
|
||
final class ResponseTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider delegateRequests | ||
*/ | ||
public function testResponseIsCreatedSuccessfully($request) | ||
{ | ||
$delegateResponse = new Response(202); | ||
$response = new Psr15Response($delegateResponse, $request); | ||
$this->assertEquals(202, $response->getStatusCode()); | ||
$this->assertSame($request, $response->getRequest()); | ||
$this->assertSame($delegateResponse, $response->unwrap()); | ||
} | ||
|
||
public function delegateRequests(): array | ||
{ | ||
return [ | ||
[null], | ||
[new Request(new Psr7Request('GET', 'http://test.com/path'))], | ||
]; | ||
} | ||
} |