Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 28, 2020
1 parent 0c980e4 commit f584fa4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 79 deletions.
96 changes: 23 additions & 73 deletions tests/Client/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,30 @@ public function requestShouldBindToStreamEventsAndUseconnector()
$request->handleData("\r\nbody");
}

/**
* @test
*/
public function requestShouldConnectViaTlsIfUrlUsesHttpsScheme()
{
$requestData = new RequestData('GET', 'https://www.example.com');
$request = new Request($this->connector, $requestData);

$this->connector->expects($this->once())->method('connect')->with('tls://www.example.com:443')->willReturn(new Promise(function () { }));

$request->end();
}

/** @test */
public function requestShouldEmitErrorIfConnectionFails()
{
$requestData = new RequestData('GET', 'http://www.example.com');
$request = new Request($this->connector, $requestData);

$this->rejectedConnectionMock();

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('RuntimeException')
);

$request->on('error', $handler);
$this->connector->expects($this->once())->method('connect')->willReturn(\React\Promise\reject(new \RuntimeException()));

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke');
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));

$request->on('close', $handler);
$request->on('close', $this->expectCallableOnce());
$request->on('end', $this->expectCallableNever());

$request->end();
Expand All @@ -121,20 +123,9 @@ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed()

$this->successfulConnectionMock();

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('RuntimeException')
);

$request->on('error', $handler);

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke');
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));

$request->on('close', $handler);
$request->on('close', $this->expectCallableOnce());
$request->on('end', $this->expectCallableNever());

$request->end();
Expand All @@ -149,20 +140,9 @@ public function requestShouldEmitErrorIfConnectionEmitsError()

$this->successfulConnectionMock();

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('Exception')
);

$request->on('error', $handler);
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('Exception')));

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke');

$request->on('close', $handler);
$request->on('close', $this->expectCallableOnce());
$request->on('end', $this->expectCallableNever());

$request->end();
Expand All @@ -177,14 +157,7 @@ public function requestShouldEmitErrorIfRequestParserThrowsException()

$this->successfulConnectionMock();

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('\InvalidArgumentException')
);

$request->on('error', $handler);
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));

$request->end();
$request->handleData("\r\n\r\n");
Expand All @@ -198,14 +171,7 @@ public function requestShouldEmitErrorIfUrlIsInvalid()
$requestData = new RequestData('GET', 'ftp://www.example.com');
$request = new Request($this->connector, $requestData);

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('\InvalidArgumentException')
);

$request->on('error', $handler);
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));

$this->connector->expects($this->never())
->method('connect');
Expand All @@ -221,14 +187,7 @@ public function requestShouldEmitErrorIfUrlHasNoScheme()
$requestData = new RequestData('GET', 'www.example.com');
$request = new Request($this->connector, $requestData);

$handler = $this->createCallableMock();
$handler->expects($this->once())
->method('__invoke')
->with(
$this->isInstanceOf('\InvalidArgumentException')
);

$request->on('error', $handler);
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));

$this->connector->expects($this->never())
->method('connect');
Expand Down Expand Up @@ -533,15 +492,6 @@ private function successfulAsyncConnectionMock()
};
}

private function rejectedConnectionMock()
{
$this->connector
->expects($this->once())
->method('connect')
->with('www.example.com:80')
->will($this->returnValue(new RejectedPromise(new \RuntimeException())));
}

/** @test */
public function multivalueHeader()
{
Expand Down
12 changes: 6 additions & 6 deletions tests/FunctionalServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort

public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
{
if (!function_exists('stream_socket_enable_crypto')) {
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$loop = Factory::create();
Expand Down Expand Up @@ -339,8 +339,8 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()

public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri()
{
if (!function_exists('stream_socket_enable_crypto')) {
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$loop = Factory::create();
Expand Down Expand Up @@ -408,8 +408,8 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort()

public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort()
{
if (!function_exists('stream_socket_enable_crypto')) {
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$loop = Factory::create();
Expand Down

0 comments on commit f584fa4

Please sign in to comment.