1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace Predis;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- use Predis\Network\IConnectionSingle;
- class CommunicationExceptionTest extends StandardTestCase
- {
-
- public function testExceptionMessage()
- {
- $message = 'Connection error message.';
- $connection = $this->getMockedConnectionBase();
- $exception = $this->getException($connection, $message);
- $this->setExpectedException('Predis\CommunicationException', $message);
- throw $exception;
- }
-
- public function testExceptionConnection()
- {
- $connection = $this->getMockedConnectionBase();
- $exception = $this->getException($connection, 'ERROR MESSAGE');
- $this->assertSame($connection, $exception->getConnection());
- }
-
- public function testShouldResetConnection()
- {
- $connection = $this->getMockedConnectionBase();
- $exception = $this->getException($connection, 'ERROR MESSAGE');
- $this->assertTrue($exception->shouldResetConnection());
- }
-
-
-
-
- protected function getMockedConnectionBase($parameters = null)
- {
- $builder = $this->getMockBuilder('Predis\Network\ConnectionBase');
- if ($parameters === null) {
- $builder->disableOriginalConstructor();
- }
- else if (!$parameters instanceof IConnectionParameters) {
- $parameters = new ConnectionParameters($parameters);
- }
- return $builder->getMockForAbstractClass(array($parameters));
- }
-
- protected function getException(IConnectionSingle $connection, $message, $code = 0, \Exception $inner = null)
- {
- $arguments = array($connection, $message, $code, $inner);
- $mock = $this->getMockForAbstractClass('Predis\CommunicationException', $arguments);
- return $mock;
- }
- }
|