|
|
@@ -30,20 +30,18 @@ class SocketHandlerTest extends TestCase
|
|
|
*/
|
|
|
private $res;
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException UnexpectedValueException
|
|
|
- */
|
|
|
public function testInvalidHostname()
|
|
|
{
|
|
|
+ $this->expectException(\UnexpectedValueException::class);
|
|
|
+
|
|
|
$this->createHandler('garbage://here');
|
|
|
$this->writeRecord('data');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException \InvalidArgumentException
|
|
|
- */
|
|
|
public function testBadConnectionTimeout()
|
|
|
{
|
|
|
+ $this->expectException(\InvalidArgumentException::class);
|
|
|
+
|
|
|
$this->createHandler('localhost:1234');
|
|
|
$this->handler->setConnectionTimeout(-1);
|
|
|
}
|
|
|
@@ -55,11 +53,10 @@ class SocketHandlerTest extends TestCase
|
|
|
$this->assertEquals(10.1, $this->handler->getConnectionTimeout());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException \InvalidArgumentException
|
|
|
- */
|
|
|
public function testBadTimeout()
|
|
|
{
|
|
|
+ $this->expectException(\InvalidArgumentException::class);
|
|
|
+
|
|
|
$this->createHandler('localhost:1234');
|
|
|
$this->handler->setTimeout(-1);
|
|
|
}
|
|
|
@@ -91,46 +88,44 @@ class SocketHandlerTest extends TestCase
|
|
|
$this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException UnexpectedValueException
|
|
|
- */
|
|
|
public function testExceptionIsThrownOnFsockopenError()
|
|
|
{
|
|
|
$this->setMockHandler(['fsockopen']);
|
|
|
$this->handler->expects($this->once())
|
|
|
->method('fsockopen')
|
|
|
->will($this->returnValue(false));
|
|
|
+
|
|
|
+ $this->expectException(\UnexpectedValueException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException UnexpectedValueException
|
|
|
- */
|
|
|
public function testExceptionIsThrownOnPfsockopenError()
|
|
|
{
|
|
|
$this->setMockHandler(['pfsockopen']);
|
|
|
$this->handler->expects($this->once())
|
|
|
->method('pfsockopen')
|
|
|
->will($this->returnValue(false));
|
|
|
+
|
|
|
$this->handler->setPersistent(true);
|
|
|
+
|
|
|
+ $this->expectException(\UnexpectedValueException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException UnexpectedValueException
|
|
|
- */
|
|
|
public function testExceptionIsThrownIfCannotSetTimeout()
|
|
|
{
|
|
|
$this->setMockHandler(['streamSetTimeout']);
|
|
|
$this->handler->expects($this->once())
|
|
|
->method('streamSetTimeout')
|
|
|
->will($this->returnValue(false));
|
|
|
+
|
|
|
+ $this->expectException(\UnexpectedValueException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException UnexpectedValueException
|
|
|
- */
|
|
|
public function testExceptionIsThrownIfCannotSetChunkSize()
|
|
|
{
|
|
|
$this->setMockHandler(array('streamSetChunkSize'));
|
|
|
@@ -138,12 +133,12 @@ class SocketHandlerTest extends TestCase
|
|
|
$this->handler->expects($this->once())
|
|
|
->method('streamSetChunkSize')
|
|
|
->will($this->returnValue(false));
|
|
|
+
|
|
|
+ $this->expectException(\UnexpectedValueException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException RuntimeException
|
|
|
- */
|
|
|
public function testWriteFailsOnIfFwriteReturnsFalse()
|
|
|
{
|
|
|
$this->setMockHandler(['fwrite']);
|
|
|
@@ -161,12 +156,11 @@ class SocketHandlerTest extends TestCase
|
|
|
->method('fwrite')
|
|
|
->will($this->returnCallback($callback));
|
|
|
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException RuntimeException
|
|
|
- */
|
|
|
public function testWriteFailsIfStreamTimesOut()
|
|
|
{
|
|
|
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
|
|
@@ -187,12 +181,11 @@ class SocketHandlerTest extends TestCase
|
|
|
->method('streamGetMetadata')
|
|
|
->will($this->returnValue(['timed_out' => true]));
|
|
|
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException RuntimeException
|
|
|
- */
|
|
|
public function testWriteFailsOnIncompleteWrite()
|
|
|
{
|
|
|
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
|
|
@@ -211,6 +204,8 @@ class SocketHandlerTest extends TestCase
|
|
|
->method('streamGetMetadata')
|
|
|
->will($this->returnValue(['timed_out' => false]));
|
|
|
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|
|
|
@@ -263,9 +258,6 @@ class SocketHandlerTest extends TestCase
|
|
|
$this->assertTrue(is_resource($this->res));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @expectedException \RuntimeException
|
|
|
- */
|
|
|
public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()
|
|
|
{
|
|
|
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
|
|
@@ -280,6 +272,8 @@ class SocketHandlerTest extends TestCase
|
|
|
|
|
|
$this->handler->setWritingTimeout(1);
|
|
|
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+
|
|
|
$this->writeRecord('Hello world');
|
|
|
}
|
|
|
|