|
@@ -21,35 +21,34 @@ class CommunicationExceptionTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testExceptionMessage()
|
|
|
+ public function testExceptionReturnsInnerConnection()
|
|
|
{
|
|
|
- $message = 'Connection error message.';
|
|
|
- $connection = $this->getMockedConnectionBase();
|
|
|
- $exception = $this->getException($connection, $message);
|
|
|
-
|
|
|
- $this->setExpectedException('Predis\CommunicationException', $message);
|
|
|
+ $connection = $this->getMockConnection();
|
|
|
+ $exception = $this->createMockException($connection, 'Communication error message');
|
|
|
|
|
|
- throw $exception;
|
|
|
+ $this->assertSame($connection, $exception->getConnection());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
+ * @expectedException \Predis\CommunicationException
|
|
|
+ * @expectedExceptionMessage Connection error message
|
|
|
*/
|
|
|
- public function testExceptionConnection()
|
|
|
+ public function testExceptionMessage()
|
|
|
{
|
|
|
- $connection = $this->getMockedConnectionBase();
|
|
|
- $exception = $this->getException($connection, 'ERROR MESSAGE');
|
|
|
+ $connection = $this->getMockConnection();
|
|
|
+ $exception = $this->createMockException($connection, 'Connection error message');
|
|
|
|
|
|
- $this->assertSame($connection, $exception->getConnection());
|
|
|
+ throw $exception;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testShouldResetConnection()
|
|
|
+ public function testShouldResetConnectionIsTrue()
|
|
|
{
|
|
|
- $connection = $this->getMockedConnectionBase();
|
|
|
- $exception = $this->getException($connection, 'ERROR MESSAGE');
|
|
|
+ $connection = $this->getMockConnection();
|
|
|
+ $exception = $this->createMockException($connection, 'Communication error message');
|
|
|
|
|
|
$this->assertTrue($exception->shouldResetConnection());
|
|
|
}
|
|
@@ -57,43 +56,55 @@ class CommunicationExceptionTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
* @expectedException \Predis\CommunicationException
|
|
|
- * @expectedExceptionMessage Communication error
|
|
|
+ * @expectedExceptionMessage Communication error message
|
|
|
*/
|
|
|
public function testCommunicationExceptionHandling()
|
|
|
{
|
|
|
- $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
|
|
|
- $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
|
|
|
- $connection->expects($this->once())->method('disconnect');
|
|
|
+ $connection = $this->getMockConnection();
|
|
|
+ $connection
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isConnected')
|
|
|
+ ->will($this->returnValue(true));
|
|
|
+ $connection
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('disconnect');
|
|
|
|
|
|
- $exception = $this->getException($connection, 'Communication error');
|
|
|
+ $exception = $this->createMockException($connection, 'Communication error message');
|
|
|
|
|
|
CommunicationException::handle($exception);
|
|
|
}
|
|
|
|
|
|
- // ******************************************************************** //
|
|
|
- // ---- HELPER METHODS ------------------------------------------------ //
|
|
|
- // ******************************************************************** //
|
|
|
-
|
|
|
/**
|
|
|
- * Returns a mocked connection instance.
|
|
|
- *
|
|
|
- * @param mixed $parameters Connection parameters.
|
|
|
- *
|
|
|
- * @return Connection\NodeConnectionInterface
|
|
|
+ * @group disconnected
|
|
|
+ * @expectedException \Predis\CommunicationException
|
|
|
+ * @expectedExceptionMessage Communication error message
|
|
|
*/
|
|
|
- protected function getMockedConnectionBase($parameters = null)
|
|
|
+ public function testCommunicationExceptionHandlingWhenShouldResetConnectionIsFalse()
|
|
|
{
|
|
|
- $builder = $this->getMockBuilder('Predis\Connection\AbstractConnection');
|
|
|
-
|
|
|
- if ($parameters === null) {
|
|
|
- $builder->disableOriginalConstructor();
|
|
|
- } elseif (!$parameters instanceof Connection\ParametersInterface) {
|
|
|
- $parameters = new Connection\Parameters($parameters);
|
|
|
- }
|
|
|
+ $connection = $this->getMockConnection();
|
|
|
+ $connection
|
|
|
+ ->expects($this->never())
|
|
|
+ ->method('isConnected');
|
|
|
+ $connection
|
|
|
+ ->expects($this->never())
|
|
|
+ ->method('disconnect');
|
|
|
+
|
|
|
+ $exception = $this->getMockBuilder('Predis\CommunicationException')
|
|
|
+ ->setConstructorArgs(array($connection, 'Communication error message'))
|
|
|
+ ->setMethods(array('shouldResetConnection'))
|
|
|
+ ->getMockForAbstractClass();
|
|
|
+ $exception
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('shouldResetConnection')
|
|
|
+ ->will($this->returnValue(false));
|
|
|
|
|
|
- return $builder->getMockForAbstractClass(array($parameters));
|
|
|
+ CommunicationException::handle($exception);
|
|
|
}
|
|
|
|
|
|
+ // ******************************************************************** //
|
|
|
+ // ---- HELPER METHODS ------------------------------------------------ //
|
|
|
+ // ******************************************************************** //
|
|
|
+
|
|
|
/**
|
|
|
* Returns a connection exception instance.
|
|
|
*
|
|
@@ -104,15 +115,14 @@ class CommunicationExceptionTest extends PredisTestCase
|
|
|
*
|
|
|
* @return \Predis\CommunicationException
|
|
|
*/
|
|
|
- protected function getException(
|
|
|
+ protected function createMockException(
|
|
|
Connection\NodeConnectionInterface $connection,
|
|
|
$message,
|
|
|
$code = 0,
|
|
|
\Exception $inner = null
|
|
|
) {
|
|
|
- $arguments = array($connection, $message, $code, $inner);
|
|
|
- $mock = $this->getMockForAbstractClass('Predis\CommunicationException', $arguments);
|
|
|
-
|
|
|
- return $mock;
|
|
|
+ return $this->getMockBuilder('Predis\CommunicationException')
|
|
|
+ ->setConstructorArgs(array($connection, $message, $code, $inner))
|
|
|
+ ->getMockForAbstractClass();
|
|
|
}
|
|
|
}
|