-
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.
Merge pull request #47 from jcchavezs/adds_curl_integration
Adds cURL integration test.
- Loading branch information
Showing
3 changed files
with
101 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace ZipkinTests\Integration\Reporters\Http; | ||
|
||
use Exception; | ||
use HttpTest\HttpTestServer; | ||
use PHPUnit_Framework_TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use RuntimeException; | ||
use Zipkin\Reporters\Http\CurlFactory; | ||
|
||
final class CurlFactoryTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testHttpReportingSuccess() | ||
{ | ||
$t = $this; | ||
|
||
$server = HttpTestServer::create( | ||
function (RequestInterface $request, ResponseInterface &$response) use ($t) { | ||
$t->assertEquals('POST', $request->getMethod()); | ||
$t->assertEquals('application/json', $request->getHeader('Content-Type')[0]); | ||
$response = $response->withStatus(202); | ||
} | ||
); | ||
|
||
$pid = pcntl_fork(); | ||
|
||
if ($pid === -1) { | ||
$this->fail('Error forking thread.'); | ||
} elseif ($pid) { | ||
$server->start(); | ||
} else { | ||
$server->waitForReady(); | ||
|
||
try { | ||
$curlClient = CurlFactory::create()->build([ | ||
'endpoint_url' => $server->getUrl(), | ||
]); | ||
|
||
$curlClient(json_encode([])); | ||
} catch (Exception $e) { | ||
$this->fail($e->getMessage()); | ||
} finally { | ||
$server->stop(); | ||
} | ||
} | ||
} | ||
|
||
public function testHttpReportingFailsDueToInvalidStatusCode() | ||
{ | ||
$server = HttpTestServer::create( | ||
function (RequestInterface $request, ResponseInterface &$response) { | ||
$response = $response->withStatus(404); | ||
} | ||
); | ||
|
||
$pid = pcntl_fork(); | ||
|
||
if ($pid === -1) { | ||
$this->fail('Error forking thread.'); | ||
} elseif ($pid) { | ||
$server->start(); | ||
} else { | ||
$server->waitForReady(); | ||
|
||
try { | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Reporting of spans failed'); | ||
|
||
$curlClient = CurlFactory::create()->build([ | ||
'endpoint_url' => $server->getUrl(), | ||
]); | ||
|
||
$curlClient(''); | ||
|
||
$this->fail('Runtime exception expected'); | ||
} finally { | ||
$server->stop(); | ||
} | ||
} | ||
} | ||
|
||
public function testHttpReportingFailsDueToUnreachableUrl() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Reporting of spans failed'); | ||
|
||
$curlClient = CurlFactory::create()->build([ | ||
'endpoint_url' => 'invalid_url', | ||
]); | ||
|
||
$curlClient(''); | ||
} | ||
} |