diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 762e0b04..ecc1b192 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: redis: image: redis:${{ matrix.redis-versions }} ports: - - 6379/tcp + - 6379:6379 options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: fail-fast: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dc3ddb95..bd9a342b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,8 +8,6 @@ processIsolation="false" stopOnError="false" stopOnFailure="false" - syntaxCheck="true" - beStrictAboutTestSize="true" beStrictAboutTestsThatDoNotTestAnything="true"> diff --git a/tests/PHPUnit/PredisConnectionTestCase.php b/tests/PHPUnit/PredisConnectionTestCase.php index fb3445a1..31ef67cc 100644 --- a/tests/PHPUnit/PredisConnectionTestCase.php +++ b/tests/PHPUnit/PredisConnectionTestCase.php @@ -80,11 +80,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'udp'. */ public function testThrowsExceptionOnInvalidScheme() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'udp'"); + $this->createConnectionWithParams(array('scheme' => 'udp')); } @@ -195,7 +196,7 @@ abstract class PredisConnectionTestCase extends PredisTestCase $connection = $this->createConnection(); $this->assertFalse($connection->isConnected()); - $this->assertInternalType('resource', $connection->getResource()); + $this->assertIsResource($connection->getResource()); $this->assertTrue($connection->isConnected()); } @@ -220,9 +221,11 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $commands = $this->getCommandFactory(); - $cmdPing = $this->getMock($commands->getCommandClass('ping'), array('parseResponse')); + $cmdPing = $this->getMockBuilder($commands->getCommandClass('ping')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdPing->expects($this->never()) - ->method('parseResponse'); + ->method('parseResponse'); $connection = $this->createConnection(); @@ -271,7 +274,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $commands = $this->getCommandFactory(); - $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($commands->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); $cmdEcho ->expects($this->never()) @@ -289,7 +294,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $commands = $this->getCommandFactory(); - $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($commands->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); $cmdEcho ->expects($this->never()) @@ -308,14 +315,20 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $commands = $this->getCommandFactory(); - $cmdPing = $this->getMock($commands->getCommandClass('ping'), array('parseResponse')); - $cmdPing->expects($this->never()) - ->method('parseResponse'); + $cmdPing = $this->getMockBuilder($commands->getCommandClass('ping')) + ->setMethods(array('parseResponse')) + ->getMock(); + $cmdPing + ->expects($this->never()) + ->method('parseResponse'); - $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($commands->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); - $cmdEcho->expects($this->never()) - ->method('parseResponse'); + $cmdEcho + ->expects($this->never()) + ->method('parseResponse'); $connection = $this->createConnection(); @@ -333,13 +346,18 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $commands = $this->getCommandFactory(); - $cmdPing = $this->getMock($commands->getCommandClass('ping'), array('getArguments')); + $cmdPing = $this->getMockBuilder($commands->getCommandClass('ping')) + ->setMethods(array('getArguments')) + ->getMock(); $cmdPing ->expects($this->once()) ->method('getArguments') ->will($this->returnValue(array())); - $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('getArguments')); + $cmdEcho = $this->getMockBuilder($commands->getCommandClass('echo')) + ->setMethods(array('getArguments')) + ->getMock(); + $cmdEcho->setArguments(array('ECHOED')); $cmdEcho ->expects($this->once()) ->method('getArguments') @@ -435,11 +453,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[tcp:\/\/169.254.10.10:6379\]/ */ public function testThrowsExceptionOnConnectionTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[tcp:\/\/169.254.10.10:6379\]/'); + // TODO: float timeouts for connect() under HHVM 3.6.6 are broken and, // unfortunately, this is the version still being used by Travis CI. if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.6.6', '<=')) { @@ -459,11 +478,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[tcp:\/\/\[0:0:0:0:0:ffff:a9fe:a0a\]:6379\]/ */ public function testThrowsExceptionOnConnectionTimeoutIPv6() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[tcp:\/\/\[0:0:0:0:0:ffff:a9fe:a0a\]:6379\]/'); + // TODO: float timeouts for connect() under HHVM 3.6.6 are broken and, // unfortunately, this is the version still being used by Travis CI. if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.6.6', '<=')) { @@ -483,11 +503,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[unix:\/tmp\/nonexistent\/redis\.sock]/ */ public function testThrowsExceptionOnUnixDomainSocketNotFound() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[unix:\/tmp\/nonexistent\/redis\.sock]/'); + $connection = $this->createConnectionWithParams(array( 'scheme' => 'unix', 'path' => '/tmp/nonexistent/redis.sock', @@ -499,10 +520,11 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowsExceptionOnReadWriteTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $commands = $this->getCommandFactory(); $connection = $this->createConnectionWithParams(array( @@ -515,10 +537,11 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $stream = $connection->getResource(); diff --git a/tests/PHPUnit/PredisDistributorTestCase.php b/tests/PHPUnit/PredisDistributorTestCase.php index d3dd26e9..e9879194 100644 --- a/tests/PHPUnit/PredisDistributorTestCase.php +++ b/tests/PHPUnit/PredisDistributorTestCase.php @@ -68,7 +68,7 @@ abstract class PredisDistributorTestCase extends PredisTestCase */ public function testEmptyRingThrowsException() { - $this->setExpectedException('Predis\Cluster\Distributor\EmptyRingException'); + $this->expectException('Predis\Cluster\Distributor\EmptyRingException'); $distributor = $this->getDistributorInstance(); $distributor->getByHash('nodehash'); diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index daab92a4..9552b850 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -20,6 +20,14 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase { protected $redisServerVersion = null; + /** + * {@inheritdoc} + */ + protected function setUp(): void + { + $this->checkRequirements(); + } + /** * Sleep the test case with microseconds resolution. * @@ -196,7 +204,9 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase */ protected function getMockConnectionOfType($interface, $parameters = null) { - $connection = $this->getMock($interface); + $connection = $this->getMockBuilder($interface)->getMock(); + + // TODO: verify that $connection is an instance of \Predis\Connection\NodeConnectionInterface if ($parameters) { $parameters = Connection\Parameters::create($parameters); @@ -331,8 +341,6 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase */ protected function checkRequirements() { - parent::checkRequirements(); - $this->checkRequiredRedisServerVersion(); } } diff --git a/tests/Predis/ClientExceptionTest.php b/tests/Predis/ClientExceptionTest.php index 73471495..3f8e7907 100644 --- a/tests/Predis/ClientExceptionTest.php +++ b/tests/Predis/ClientExceptionTest.php @@ -25,7 +25,8 @@ class ClientExceptionTest extends PredisTestCase { $message = 'This is a client exception.'; - $this->setExpectedException('Predis\ClientException', $message); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage($message); throw new ClientException($message); } diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index bf4fa6fc..d2f657a3 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -92,11 +92,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Array of connection parameters requires `cluster`, `replication` or `aggregate` client option */ public function testConstructorThrowsExceptionWithArrayOfParametersArgumentAndMissingOption() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Array of connection parameters requires `cluster`, `replication` or `aggregate` client option'); + $arg1 = array( array('host' => 'localhost', 'port' => 7000), array('host' => 'localhost', 'port' => 7001), @@ -154,8 +155,8 @@ class ClientTest extends PredisTestCase public function testConstructorWithArrayOfConnectionsArgument() { $arg1 = array( - $this->getMock('Predis\Connection\NodeConnectionInterface'), - $this->getMock('Predis\Connection\NodeConnectionInterface'), + $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(), + $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(), ); $client = new Client($arg1, array( @@ -220,9 +221,11 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithCallableArgument() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -236,14 +239,17 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Callable parameters must return a valid connection */ public function testConstructorWithCallableConnectionInitializerThrowsExceptionOnInvalidReturnType() { - $wrongType = $this->getMock('stdClass'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Callable parameters must return a valid connection'); - $callable = $this->getMock('stdClass', array('__invoke')); + $wrongType = $this->getMockBuilder('stdClass')->getMock(); + + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -258,7 +264,7 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithNullAndArrayArgument() { - $connections = $this->getMock('Predis\Connection\FactoryInterface'); + $connections = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $arg2 = array('prefix' => 'prefix:', 'connections' => $connections); $client = new Client(null, $arg2); @@ -289,21 +295,27 @@ class ClientTest extends PredisTestCase { $arg1 = array('tcp://host1', 'tcp://host2'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $fncluster = $this->getMock('stdClass', array('__invoke')); + $fncluster = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fncluster ->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1) ->will($this->returnValue($connection)); - $fnreplication = $this->getMock('stdClass', array('__invoke')); + $fnreplication = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnreplication ->expects($this->never()) ->method('__invoke'); - $fnaggregate = $this->getMock('stdClass', array('__invoke')); + $fnaggregate = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnaggregate ->expects($this->never()) ->method('__invoke'); @@ -326,17 +338,23 @@ class ClientTest extends PredisTestCase { $arg1 = array('tcp://host1', 'tcp://host2'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $fnreplication = $this->getMock('stdClass', array('__invoke')); + $fnreplication = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnreplication ->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1) ->will($this->returnValue($connection)); - $fnaggregate = $this->getMock('stdClass', array('__invoke')); - $fnaggregate->expects($this->never())->method('__invoke'); + $fnaggregate = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); + $fnaggregate + ->expects($this->never()) + ->method('__invoke'); $arg2 = array( 'replication' => $fnreplication, @@ -344,8 +362,6 @@ class ClientTest extends PredisTestCase ); $client = new Client($arg1, $arg2); - - $this->assertSame($connection, $client->getConnection()); } /** @@ -355,16 +371,18 @@ class ClientTest extends PredisTestCase { $arg1 = array('tcp://host1', 'tcp://host2'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $fnaggregate = $this->getMock('stdClass', array('__invoke')); + $fnaggregate = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnaggregate ->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1) ->will($this->returnValue($connection)); - $connections = $this->getMock('Predis\Connection\FactoryInterface'); + $connections = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $connections ->expects($this->never()) ->method('aggregate'); @@ -378,21 +396,23 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid type for connection parameters */ public function testConstructorWithInvalidArgumentType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid type for connection parameters'); + $client = new Client(new \stdClass()); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid type for client options */ public function testConstructorWithInvalidOptionType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid type for client options'); + $client = new Client('tcp://host1', new \stdClass()); } @@ -401,7 +421,7 @@ class ClientTest extends PredisTestCase */ public function testConnectAndDisconnect() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('connect'); @@ -419,7 +439,7 @@ class ClientTest extends PredisTestCase */ public function testIsConnectedChecksConnectionState() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('isConnected'); @@ -433,7 +453,7 @@ class ClientTest extends PredisTestCase */ public function testQuitIsAliasForDisconnect() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('disconnect'); @@ -449,7 +469,7 @@ class ClientTest extends PredisTestCase { $ping = $this->getCommandFactory()->createCommand('ping', array()); - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('createCommand') @@ -470,7 +490,7 @@ class ClientTest extends PredisTestCase $ping = $commands->createCommand('ping', array()); $hgetall = $commands->createCommand('hgetall', array('metavars', 'foo', 'hoge')); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->at(0)) ->method('executeCommand') @@ -490,15 +510,16 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testExecuteCommandThrowsExceptionOnRedisError() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $ping = $this->getCommandFactory()->createCommand('ping', array()); $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') @@ -516,7 +537,7 @@ class ClientTest extends PredisTestCase $ping = $this->getCommandFactory()->createCommand('ping', array()); $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') @@ -535,14 +556,14 @@ class ClientTest extends PredisTestCase { $ping = $this->getCommandFactory()->createCommand('ping', array()); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') ->with($this->isInstanceOf('Predis\Command\Redis\PING')) ->will($this->returnValue('PONG')); - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('createCommand') @@ -550,21 +571,25 @@ class ClientTest extends PredisTestCase ->will($this->returnValue($ping)); $options = array('commands' => $commands); - $client = $this->getMock('Predis\Client', null, array($connection, $options)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(null) + ->setConstructorArgs(array($connection, $options)) + ->getMock(); $this->assertEquals('PONG', $client->ping()); } /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testCallingRedisCommandThrowsExceptionOnServerError() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') @@ -582,7 +607,7 @@ class ClientTest extends PredisTestCase { $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') @@ -600,7 +625,7 @@ class ClientTest extends PredisTestCase */ public function testRawCommand() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->at(0)) ->method('executeCommand') @@ -632,7 +657,7 @@ class ClientTest extends PredisTestCase */ public function testRawCommandNeverAppliesPrefix() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->at(0)) ->method('executeCommand') @@ -658,7 +683,7 @@ class ClientTest extends PredisTestCase $message = 'ERR Mock error response'; $response = new Response\Error($message); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') @@ -673,11 +698,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Command 'INVALIDCOMMAND' is not a registered Redis command. */ public function testThrowsExceptionOnNonRegisteredRedisCommand() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("Command 'INVALIDCOMMAND' is not a registered Redis command"); + $client = new Client(); $client->invalidCommand(); } @@ -687,8 +713,14 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodReturnsInstanceOfSubclass() { - $nodes = array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'); - $client = $this->getMock('Predis\Client', array('dummy'), array($nodes, array('cluster' => 'predis')), 'SubclassedClient'); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(null) + ->setConstructorArgs(array( + array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'), + array('cluster' => 'predis'), + )) + ->setMockClassName('SubclassedClient') + ->getMock(); $this->assertInstanceOf('SubclassedClient', $client->getClientBy('alias', 'node02')); } @@ -701,7 +733,9 @@ class ClientTest extends PredisTestCase $test = $this; $client = new Client(array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'), array('cluster' => 'predis')); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -723,7 +757,7 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodSupportsSelectingConnectionById() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionById')) @@ -743,12 +777,13 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Cannot find a connection by id matching `127.0.0.1:7000` */ public function testGetClientByMethodThrowsExceptionSelectingConnectionByUnknownId() { - $aggregate = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Cannot find a connection by id matching `127.0.0.1:7000`'); + + $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); $aggregate ->expects($this->once()) ->method('getConnectionById') @@ -764,7 +799,7 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodSupportsSelectingConnectionByAlias() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionByAlias')) @@ -787,7 +822,7 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodSupportsSelectingConnectionByKey() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionByKey')) @@ -810,7 +845,7 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodSupportsSelectingConnectionBySlot() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionBySlot')) @@ -833,7 +868,7 @@ class ClientTest extends PredisTestCase */ public function testGetClientByMethodSupportsSelectingConnectionByRole() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionByRole')) @@ -857,7 +892,7 @@ class ClientTest extends PredisTestCase public function testGetClientByMethodSupportsSelectingConnectionByCommand() { $command = \Predis\Command\RawCommand::create('GET', 'key'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface') ->setMethods(array('getConnectionByCommand')) @@ -877,11 +912,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid selector type: `unknown` */ public function testGetClientByMethodThrowsExceptionWhenSelectingConnectionByUnknownType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid selector type: `unknown`'); + $client = new Client('tcp://127.0.0.1?alias=node01'); $client->getClientBy('unknown', 'test'); @@ -889,11 +925,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Selecting connection by id is not supported by Predis\Connection\StreamConnection */ public function testGetClientByMethodThrowsExceptionWhenConnectionDoesNotSupportSelectorType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Selecting connection by id is not supported by Predis\Connection\StreamConnection'); + $client = new Client('tcp://127.0.0.1?alias=node01'); $client->getClientBy('id', 'node01'); @@ -926,7 +963,9 @@ class ClientTest extends PredisTestCase */ public function testPipelineWithCallableExecutesPipeline() { - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -951,7 +990,7 @@ class ClientTest extends PredisTestCase */ public function testPubSubLoopWithArrayReturnsPubSubConsumerWithOptions() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $options = array('subscribe' => 'channel'); $client = new Client($connection); @@ -972,13 +1011,15 @@ class ClientTest extends PredisTestCase // NOTE: we use a subscribe count of 0 in the message payload to trick // the context and forcing it to be closed since there are no more // active subscriptions. - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') ->will($this->returnValue(array('subscribe', 'channel', 0))); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke'); @@ -992,7 +1033,7 @@ class ClientTest extends PredisTestCase */ public function testPubSubLoopWithCallableReturningFalseStopsPubSubConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->at(1)) ->method('read') @@ -1006,7 +1047,9 @@ class ClientTest extends PredisTestCase ->method('read') ->will($this->returnValue(array('unsubscribe', 'channel', 0))); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->at(0)) ->method('__invoke') @@ -1056,13 +1099,15 @@ class ClientTest extends PredisTestCase // We use CAS here as we don't care about the actual MULTI/EXEC context. $options = array('cas' => true, 'retry' => 3); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('executeCommand') ->will($this->returnValue(new Response\Status('QUEUED'))); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -1077,7 +1122,7 @@ class ClientTest extends PredisTestCase */ public function testMonitorReturnsMonitorConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $this->assertInstanceOf('Predis\Monitor\Consumer', $monitor = $client->monitor()); @@ -1099,7 +1144,7 @@ class ClientTest extends PredisTestCase ->with('OK') ->will($this->returnValue(true)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->at(0)) ->method('executeCommand') @@ -1154,12 +1199,13 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The underlying connection is not traversable */ public function testGetIteratorWithNonTraversableConnectionThrowsException() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('The underlying connection is not traversable'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $client->getIterator(); @@ -1203,9 +1249,11 @@ class ClientTest extends PredisTestCase */ protected function getAggregateInitializer($parameters) { - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') diff --git a/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php b/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php index e6dbee55..86ac70ac 100644 --- a/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php +++ b/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php @@ -20,10 +20,11 @@ class EmptyRingExceptionTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\Cluster\Distributor\EmptyRingException */ public function testExceptionMessage() { + $this->expectException('Predis\Cluster\Distributor\EmptyRingException'); + $this->expectExceptionMessage('Empty Ring'); throw new EmptyRingException('Empty Ring'); } } diff --git a/tests/Predis/Cluster/Distributor/HashRingTest.php b/tests/Predis/Cluster/Distributor/HashRingTest.php index 1d89aae8..1bbc3baf 100644 --- a/tests/Predis/Cluster/Distributor/HashRingTest.php +++ b/tests/Predis/Cluster/Distributor/HashRingTest.php @@ -195,7 +195,9 @@ class HashRingTest extends PredisDistributorTestCase public function testCallbackToGetNodeHash() { $node = '127.0.0.1:7000'; - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) diff --git a/tests/Predis/Cluster/Distributor/KetamaRingTest.php b/tests/Predis/Cluster/Distributor/KetamaRingTest.php index b7494a26..e1555e00 100644 --- a/tests/Predis/Cluster/Distributor/KetamaRingTest.php +++ b/tests/Predis/Cluster/Distributor/KetamaRingTest.php @@ -196,7 +196,9 @@ class KetamaRingTest extends PredisDistributorTestCase public function testCallbackToGetNodeHash() { $node = '127.0.0.1:7000'; - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) diff --git a/tests/Predis/Cluster/PredisStrategyTest.php b/tests/Predis/Cluster/PredisStrategyTest.php index 8b95a980..a5e81492 100644 --- a/tests/Predis/Cluster/PredisStrategyTest.php +++ b/tests/Predis/Cluster/PredisStrategyTest.php @@ -224,7 +224,9 @@ class PredisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $arguments = array('{key}:1', '{key}:2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -264,7 +266,9 @@ class PredisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $commands = $this->getCommandFactory(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -290,7 +294,7 @@ class PredisStrategyTest extends PredisTestCase { $strategy = new PredisStrategy(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $strategy->getDistributor()->add($connection); return $strategy; diff --git a/tests/Predis/Cluster/RedisStrategyTest.php b/tests/Predis/Cluster/RedisStrategyTest.php index ad7a5759..dedcc10a 100644 --- a/tests/Predis/Cluster/RedisStrategyTest.php +++ b/tests/Predis/Cluster/RedisStrategyTest.php @@ -239,7 +239,9 @@ class RedisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $arguments = array('key:1', 'value1'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -279,7 +281,9 @@ class RedisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $commands = $this->getCommandFactory(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -294,11 +298,12 @@ class RedisStrategyTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Predis\Cluster\RedisStrategy does not provide an external distributor */ public function testThrowsExceptionOnGetDistributorMethod() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Predis\Cluster\RedisStrategy does not provide an external distributor'); + $strategy = $this->getClusterStrategy(); $strategy->getDistributor(); } diff --git a/tests/Predis/Cluster/SlotMapTest.php b/tests/Predis/Cluster/SlotMapTest.php index ea75d6e1..dc4a0390 100644 --- a/tests/Predis/Cluster/SlotMapTest.php +++ b/tests/Predis/Cluster/SlotMapTest.php @@ -139,11 +139,12 @@ class SlotMapTest extends PredisTestCase /** * @group disconnected - * @expectedException \OutOfBoundsException - * @expectedExceptionMessage Invalid slot range 0-16384 for `127.0.0.1:6379` */ public function testSetSlotsThrowsExceptionOnInvalidSlotRange() { + $this->expectException('OutOfBoundsException'); + $this->expectExceptionMessage('Invalid slot range 0-16384 for `127.0.0.1:6379`'); + $slotmap = new SlotMap(); $slotmap->setSlots(0, 16384, '127.0.0.1:6379'); @@ -195,11 +196,12 @@ class SlotMapTest extends PredisTestCase /** * @group disconnected - * @expectedException \OutOfBoundsException - * @expectedExceptionMessage Invalid slot range 0-16384 */ public function testGetSlotsThrowsExceptionOnInvalidSlotRange() { + $this->expectException('OutOfBoundsException'); + $this->expectExceptionMessage('Invalid slot range 0-16384'); + $slotmap = new SlotMap(); $slotmap->getSlots(0, 16384); @@ -439,11 +441,12 @@ class SlotMapTest extends PredisTestCase /** * @group disconnected - * @expectedException \OutOfBoundsException - * @expectedExceptionMessage Invalid slot 16384 for `127.0.0.1:6379` */ public function testOffsetSetThrowsExceptionOnInvalidSlot() { + $this->expectException('OutOfBoundsException'); + $this->expectExceptionMessage('Invalid slot 16384 for `127.0.0.1:6379`'); + $slotmap = new SlotMap(); $slotmap[16384] = '127.0.0.1:6379'; diff --git a/tests/Predis/Collection/Iterator/HashKeyTest.php b/tests/Predis/Collection/Iterator/HashKeyTest.php index c9eb743a..2d79769c 100644 --- a/tests/Predis/Collection/Iterator/HashKeyTest.php +++ b/tests/Predis/Collection/Iterator/HashKeyTest.php @@ -20,18 +20,19 @@ class HashKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'HSCAN' is not supported by the current command factory. */ public function testThrowsExceptionOnMissingCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'HSCAN' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->any()) ->method('supportsCommand') ->will($this->returnValue(false)); - $client = $this->getMock('Predis\ClientInterface'); + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -45,7 +46,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -71,7 +74,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithIntegerFields() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -115,7 +120,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -154,7 +161,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -200,7 +209,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -241,7 +252,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -294,7 +307,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -328,7 +343,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -369,7 +386,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -403,7 +422,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -444,7 +465,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -478,7 +501,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -519,7 +544,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'hscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') diff --git a/tests/Predis/Collection/Iterator/KeyspaceTest.php b/tests/Predis/Collection/Iterator/KeyspaceTest.php index c39bda11..a08b1cb6 100644 --- a/tests/Predis/Collection/Iterator/KeyspaceTest.php +++ b/tests/Predis/Collection/Iterator/KeyspaceTest.php @@ -20,18 +20,19 @@ class KeyspaceTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'SCAN' is not supported by the current command factory. */ public function testThrowsExceptionOnMissingCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'SCAN' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->any()) ->method('supportsCommand') ->will($this->returnValue(false)); - $client = $this->getMock('Predis\ClientInterface'); + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -45,7 +46,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -69,7 +72,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -108,7 +113,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -154,7 +161,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -195,7 +204,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -248,7 +259,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -282,7 +295,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -323,7 +338,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -357,7 +374,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -396,7 +415,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -430,7 +451,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -471,7 +494,9 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'scan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') diff --git a/tests/Predis/Collection/Iterator/ListKeyTest.php b/tests/Predis/Collection/Iterator/ListKeyTest.php index 07e19758..310fe1f7 100644 --- a/tests/Predis/Collection/Iterator/ListKeyTest.php +++ b/tests/Predis/Collection/Iterator/ListKeyTest.php @@ -20,18 +20,21 @@ class ListKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'LRANGE' is not supported by the current command factory. */ public function testThrowsExceptionOnMissingCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'LRANGE' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->any()) ->method('supportsCommand') ->will($this->returnValue(false)); - $client = $this->getMock('Predis\ClientInterface'); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -45,7 +48,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -69,7 +74,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -108,7 +115,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -123,10 +132,11 @@ class ListKeyTest extends PredisTestCase 'item:6', 'item:7', 'item:8', 'item:9', 'item:10', ) )); - $client->expects($this->at(2)) - ->method('lrange') - ->with('key:list', 10, 19) - ->will($this->returnValue(array('item:11', 'item:12'))); + $client + ->expects($this->at(2)) + ->method('lrange') + ->with('key:list', 10, 19) + ->will($this->returnValue(array('item:11', 'item:12'))); $iterator = new ListKey($client, 'key:list'); @@ -141,12 +151,15 @@ class ListKeyTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The $count argument must be a positive integer. */ public function testThrowsExceptionOnConstructorWithNonIntegerCountParameter() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The $count argument must be a positive integer'); + + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -157,12 +170,15 @@ class ListKeyTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The $count argument must be a positive integer. */ public function testThrowsExceptionOnConstructorWithNegativeCountParameter() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The $count argument must be a positive integer'); + + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -176,7 +192,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithCountParameter() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -210,7 +228,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithCountParameterOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -256,7 +276,9 @@ class ListKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'lrange')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') diff --git a/tests/Predis/Collection/Iterator/SetKeyTest.php b/tests/Predis/Collection/Iterator/SetKeyTest.php index 9e63f081..8834e86c 100644 --- a/tests/Predis/Collection/Iterator/SetKeyTest.php +++ b/tests/Predis/Collection/Iterator/SetKeyTest.php @@ -20,18 +20,19 @@ class SetKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'SSCAN' is not supported by the current command factory. */ public function testThrowsExceptionOnMissingCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'SSCAN' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->any()) ->method('supportsCommand') ->will($this->returnValue(false)); - $client = $this->getMock('Predis\ClientInterface'); + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -45,7 +46,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -69,7 +72,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -108,7 +113,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -154,7 +161,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -195,7 +204,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -248,7 +259,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -282,7 +295,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -323,7 +338,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -357,7 +374,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -398,7 +417,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -432,7 +453,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -473,7 +496,9 @@ class SetKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'sscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') diff --git a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php b/tests/Predis/Collection/Iterator/SortedSetKeyTest.php index 6ba99b2b..782b55d4 100644 --- a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php +++ b/tests/Predis/Collection/Iterator/SortedSetKeyTest.php @@ -20,18 +20,20 @@ class SortedSetKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'ZSCAN' is not supported by the current command factory. */ public function testThrowsExceptionOnMissingCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'ZSCAN' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface') + ->getMock(); $commands ->expects($this->any()) ->method('supportsCommand') ->will($this->returnValue(false)); - $client = $this->getMock('Predis\ClientInterface'); + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -45,7 +47,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -70,7 +74,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithIntegerMembers() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -109,7 +115,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -148,7 +156,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -194,7 +204,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -235,7 +247,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -288,7 +302,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -322,7 +338,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -363,7 +381,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -397,7 +417,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -438,7 +460,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -472,7 +496,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') @@ -513,7 +539,9 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getCommandFactory', 'zscan')) + ->getMock(); $client ->expects($this->any()) ->method('getCommandFactory') diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index d37cb457..e26dd449 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -53,9 +53,14 @@ class KeyPrefixProcessorTest extends PredisTestCase { $prefix = 'prefix:'; - $command = $this->getMock('Predis\Command\PrefixableCommandInterface'); - $command->expects($this->never())->method('getId'); - $command->expects($this->once())->method('prefixKeys')->with($prefix); + $command = $this->getMockBuilder('Predis\Command\PrefixableCommandInterface')->getMock(); + $command + ->expects($this->never()) + ->method('getId'); + $command + ->expects($this->once()) + ->method('prefixKeys') + ->with($prefix); $processor = new KeyPrefixProcessor($prefix); @@ -67,12 +72,13 @@ class KeyPrefixProcessorTest extends PredisTestCase */ public function testSkipNotPrefixableCommands() { - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) - ->method('getId') - ->will($this->returnValue('unknown')); - $command->expects($this->never()) - ->method('getArguments'); + ->method('getId') + ->will($this->returnValue('unknown')); + $command + ->expects($this->never()) + ->method('getArguments'); $processor = new KeyPrefixProcessor('prefix'); @@ -287,13 +293,16 @@ class KeyPrefixProcessorTest extends PredisTestCase { $command = $this->getCommandInstance('NEWCMD', array('key', 'value')); - $callable = $this->getMock('stdClass', array('__invoke')); - $callable->expects($this->once()) - ->method('__invoke') - ->with($command, 'prefix:') - ->will($this->returnCallback(function ($command, $prefix) { - $command->setRawArguments(array('prefix:key', 'value')); - })); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); + $callable + ->expects($this->once()) + ->method('__invoke') + ->with($command, 'prefix:') + ->will($this->returnCallback(function ($command, $prefix) { + $command->setRawArguments(array('prefix:key', 'value')); + })); $processor = new KeyPrefixProcessor('prefix:'); $processor->setCommandHandler('NEWCMD', $callable); @@ -309,13 +318,16 @@ class KeyPrefixProcessorTest extends PredisTestCase { $command = $this->getCommandInstance('SET', array('key', 'value')); - $callable = $this->getMock('stdClass', array('__invoke')); - $callable->expects($this->once()) - ->method('__invoke') - ->with($command, 'prefix:') - ->will($this->returnCallback(function ($command, $prefix) { - $command->setRawArguments(array('prefix:key', 'value')); - })); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); + $callable + ->expects($this->once()) + ->method('__invoke') + ->with($command, 'prefix:') + ->will($this->returnCallback(function ($command, $prefix) { + $command->setRawArguments(array('prefix:key', 'value')); + })); $processor = new KeyPrefixProcessor('prefix:'); $processor->setCommandHandler('SET', $callable); @@ -340,11 +352,12 @@ class KeyPrefixProcessorTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Callback must be a valid callable object or NULL */ public function testCannotDefineCommandHandlerWithInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Callback must be a valid callable object or NULL'); + $processor = new KeyPrefixProcessor('prefix:'); $processor->setCommandHandler('NEWCMD', new \stdClass()); } diff --git a/tests/Predis/Command/Processor/ProcessorChainTest.php b/tests/Predis/Command/Processor/ProcessorChainTest.php index b198180e..8e1bff98 100644 --- a/tests/Predis/Command/Processor/ProcessorChainTest.php +++ b/tests/Predis/Command/Processor/ProcessorChainTest.php @@ -35,8 +35,8 @@ class ProcessorChainTest extends PredisTestCase public function testConstructorWithProcessorsArray() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -50,8 +50,8 @@ class ProcessorChainTest extends PredisTestCase public function testCountProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -65,8 +65,8 @@ class ProcessorChainTest extends PredisTestCase public function testAddProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain(); @@ -82,13 +82,13 @@ class ProcessorChainTest extends PredisTestCase public function testAddMoreProcessors() { $processors1 = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $processors2 = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors1); @@ -104,8 +104,8 @@ class ProcessorChainTest extends PredisTestCase public function testRemoveProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -122,10 +122,10 @@ class ProcessorChainTest extends PredisTestCase */ public function testRemoveProcessorNotInChain() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -139,7 +139,7 @@ class ProcessorChainTest extends PredisTestCase */ public function testRemoveProcessorFromEmptyChain() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $chain = new ProcessorChain(); $this->assertEmpty($chain->getProcessors()); @@ -154,8 +154,8 @@ class ProcessorChainTest extends PredisTestCase public function testOffsetGet() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -170,8 +170,8 @@ class ProcessorChainTest extends PredisTestCase public function testOffsetIsset() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -186,7 +186,7 @@ class ProcessorChainTest extends PredisTestCase */ public function testOffsetSet() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $chain = new ProcessorChain(); $chain[0] = $processor; @@ -196,11 +196,12 @@ class ProcessorChainTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Processor chain accepts only instances of `Predis\Command\Processor\ProcessorInterface` */ public function testOffsetSetWithInvalidType() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Processor chain accepts only instances of `Predis\Command\Processor\ProcessorInterface`'); + $chain = new ProcessorChain(); $chain[0] = new \stdClass(); } @@ -211,8 +212,8 @@ class ProcessorChainTest extends PredisTestCase public function testGetIterator() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -225,13 +226,19 @@ class ProcessorChainTest extends PredisTestCase */ public function testProcessChain() { - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); - $processor1 = $this->getMock('Predis\Command\Processor\ProcessorInterface'); - $processor1->expects($this->once())->method('process')->with($command); + $processor1 = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); + $processor1 + ->expects($this->once()) + ->method('process') + ->with($command); - $processor2 = $this->getMock('Predis\Command\Processor\ProcessorInterface'); - $processor2->expects($this->once())->method('process')->with($command); + $processor2 = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); + $processor2 + ->expects($this->once()) + ->method('process') + ->with($command); $processors = array($processor1, $processor2); diff --git a/tests/Predis/Command/RawCommandTest.php b/tests/Predis/Command/RawCommandTest.php index d29703b6..f9050f78 100644 --- a/tests/Predis/Command/RawCommandTest.php +++ b/tests/Predis/Command/RawCommandTest.php @@ -58,22 +58,6 @@ class RawCommandTest extends PredisTestCase $this->assertSame(array('foo', 'bar'), $command->getArguments()); } - /** - * The signature of RawCommand::create() requires one argument which is the - * ID of the command (other arguments are fetched dinamically). If the first - * argument is missing, PHP emits an E_WARNING. - * - * @group disconnected - */ - public function testPHPWarningOnMissingCommandIDWithStaticCreate() - { - if (version_compare(PHP_VERSION, "7.1", '>')) { - $this->markTestSkipped('only for PHP < 7.1'); - } - $this->setExpectedException('PHPUnit_Framework_Error_Warning'); - RawCommand::create(); - } - /** * The signature of RawCommand::create() requires one argument which is the * ID of the command (other arguments are fetched dinamically). If the first @@ -83,7 +67,7 @@ class RawCommandTest extends PredisTestCase */ public function testPHPExceptionOnMissingCommandIDWithStaticCreate() { - $this->setExpectedException('ArgumentCountError'); + $this->expectException('ArgumentCountError'); RawCommand::create(); } diff --git a/tests/Predis/Command/Redis/APPEND_Test.php b/tests/Predis/Command/Redis/APPEND_Test.php index b9e74bc1..43c1bd6e 100644 --- a/tests/Predis/Command/Redis/APPEND_Test.php +++ b/tests/Predis/Command/Redis/APPEND_Test.php @@ -85,11 +85,12 @@ class APPEND_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/BITCOUNT_Test.php b/tests/Predis/Command/Redis/BITCOUNT_Test.php index 2eca95d9..4cd613b0 100644 --- a/tests/Predis/Command/Redis/BITCOUNT_Test.php +++ b/tests/Predis/Command/Redis/BITCOUNT_Test.php @@ -81,11 +81,12 @@ class BITCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key', 'list'); diff --git a/tests/Predis/Command/Redis/BITFIELD_Test.php b/tests/Predis/Command/Redis/BITFIELD_Test.php index c7eed371..f018e96f 100644 --- a/tests/Predis/Command/Redis/BITFIELD_Test.php +++ b/tests/Predis/Command/Redis/BITFIELD_Test.php @@ -140,12 +140,11 @@ class BITFIELD_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { - $this->markTestSkipped('Currently skipped due issues in Redis (see antirez/redis#3259).'); + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); $redis = $this->getClient(); diff --git a/tests/Predis/Command/Redis/BITOP_Test.php b/tests/Predis/Command/Redis/BITOP_Test.php index 3b7f7580..00f76155 100644 --- a/tests/Predis/Command/Redis/BITOP_Test.php +++ b/tests/Predis/Command/Redis/BITOP_Test.php @@ -136,33 +136,36 @@ class BITOP_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR BITOP NOT must be called with a single source key. */ public function testBitwiseNOTAcceptsOnlyOneSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR BITOP NOT must be called with a single source key'); + $this->getClient()->bitop('NOT', 'key:dst', 'key:src:1', 'key:src:2'); } /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR syntax error */ public function testThrowsExceptionOnInvalidOperation() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR syntax error'); + $this->getClient()->bitop('NOOP', 'key:dst', 'key:src:1', 'key:src:2'); } /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnInvalidSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key:src:1', 'list'); diff --git a/tests/Predis/Command/Redis/BITPOS_Test.php b/tests/Predis/Command/Redis/BITPOS_Test.php index a0b79cfd..9f6ebc84 100644 --- a/tests/Predis/Command/Redis/BITPOS_Test.php +++ b/tests/Predis/Command/Redis/BITPOS_Test.php @@ -81,11 +81,12 @@ class BITPOS_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.7 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key', 'list'); $redis->bitpos('key', 0); diff --git a/tests/Predis/Command/Redis/CLIENT_Test.php b/tests/Predis/Command/Redis/CLIENT_Test.php index 6702acca..5bc4f442 100644 --- a/tests/Predis/Command/Redis/CLIENT_Test.php +++ b/tests/Predis/Command/Redis/CLIENT_Test.php @@ -130,9 +130,9 @@ BUFFER; { $redis = $this->getClient(); - $this->assertInternalType('array', $clients = $redis->client('LIST')); + $this->assertIsArray($clients = $redis->client('LIST')); $this->assertGreaterThanOrEqual(1, count($clients)); - $this->assertInternalType('array', $clients[0]); + $this->assertIsArray($clients[0]); $this->assertArrayHasKey('addr', $clients[0]); $this->assertArrayHasKey('fd', $clients[0]); $this->assertArrayHasKey('idle', $clients[0]); @@ -187,12 +187,12 @@ BUFFER; * @requiresRedisVersion >= 2.6.9 * @dataProvider invalidConnectionNameProvider * - * @expectedException \Predis\Response\ServerException - * * @param string $invalidConnectionName */ public function testInvalidSetNameOfConnection($invalidConnectionName) { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->client('SETNAME', $invalidConnectionName); } @@ -200,10 +200,11 @@ BUFFER; /** * @group connected * @requiresRedisVersion >= 2.4.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptioOnWrongModifier() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->client('FOO'); @@ -212,11 +213,12 @@ BUFFER; /** * @group connected * @requiresRedisVersion >= 2.4.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR No such client */ public function testThrowsExceptionWhenKillingUnknownClient() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR No such client'); + $redis = $this->getClient(); $redis->client('KILL', '127.0.0.1:65535'); diff --git a/tests/Predis/Command/Redis/CONFIG_Test.php b/tests/Predis/Command/Redis/CONFIG_Test.php index c381d335..b66797f1 100644 --- a/tests/Predis/Command/Redis/CONFIG_Test.php +++ b/tests/Predis/Command/Redis/CONFIG_Test.php @@ -88,7 +88,7 @@ class CONFIG_Test extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $configs = $redis->config('GET', '*')); + $this->assertIsArray($configs = $redis->config('GET', '*')); $this->assertGreaterThan(1, count($configs)); $this->assertArrayHasKey('loglevel', $configs); $this->assertArrayHasKey('appendonly', $configs); @@ -103,7 +103,7 @@ class CONFIG_Test extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $configs = $redis->config('GET', 'dbfilename')); + $this->assertIsArray($configs = $redis->config('GET', 'dbfilename')); $this->assertEquals(1, count($configs)); $this->assertArrayHasKey('dbfilename', $configs); } @@ -139,11 +139,12 @@ class CONFIG_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo */ public function testThrowsExceptionWhenSettingUnknownConfiguration() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Unsupported CONFIG parameter: foo'); + $redis = $this->getClient(); $redis->config('SET', 'foo', 'bar'); @@ -163,10 +164,11 @@ class CONFIG_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnUnknownSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->config('FOO'); diff --git a/tests/Predis/Command/Redis/DECRBY_Test.php b/tests/Predis/Command/Redis/DECRBY_Test.php index 4746e515..97bf9e33 100644 --- a/tests/Predis/Command/Redis/DECRBY_Test.php +++ b/tests/Predis/Command/Redis/DECRBY_Test.php @@ -82,11 +82,12 @@ class DECRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnDecrementValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->decrby('foo', 'bar'); @@ -94,11 +95,12 @@ class DECRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -107,11 +109,12 @@ class DECRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/DECR_Test.php b/tests/Predis/Command/Redis/DECR_Test.php index c8fe23db..9985e7ba 100644 --- a/tests/Predis/Command/Redis/DECR_Test.php +++ b/tests/Predis/Command/Redis/DECR_Test.php @@ -81,11 +81,12 @@ class DECR_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -94,11 +95,12 @@ class DECR_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/DISCARD_Test.php b/tests/Predis/Command/Redis/DISCARD_Test.php index a903bec5..6c141168 100644 --- a/tests/Predis/Command/Redis/DISCARD_Test.php +++ b/tests/Predis/Command/Redis/DISCARD_Test.php @@ -70,11 +70,12 @@ class DISCARD_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR DISCARD without MULTI */ public function testThrowsExceptionWhenCallingOutsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR DISCARD without MULTI'); + $redis = $this->getClient(); $redis->discard(); diff --git a/tests/Predis/Command/Redis/EVALSHA_Test.php b/tests/Predis/Command/Redis/EVALSHA_Test.php index c34c5f7b..509e646a 100644 --- a/tests/Predis/Command/Redis/EVALSHA_Test.php +++ b/tests/Predis/Command/Redis/EVALSHA_Test.php @@ -83,10 +83,11 @@ class EVALSHA_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnWrongNumberOfKeys() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; @@ -99,10 +100,11 @@ class EVALSHA_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidScript() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->evalsha('ffffffffffffffffffffffffffffffffffffffff', 0); diff --git a/tests/Predis/Command/Redis/EVAL_Test.php b/tests/Predis/Command/Redis/EVAL_Test.php index 645a7614..e0428909 100644 --- a/tests/Predis/Command/Redis/EVAL_Test.php +++ b/tests/Predis/Command/Redis/EVAL_Test.php @@ -81,10 +81,11 @@ class EVAL_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnWrongNumberOfKeys() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; @@ -94,10 +95,11 @@ class EVAL_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidScript() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->eval('invalid', 0); diff --git a/tests/Predis/Command/Redis/EXEC_Test.php b/tests/Predis/Command/Redis/EXEC_Test.php index 5960dafc..e9d89bb4 100644 --- a/tests/Predis/Command/Redis/EXEC_Test.php +++ b/tests/Predis/Command/Redis/EXEC_Test.php @@ -100,11 +100,12 @@ class EXEC_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR EXEC without MULTI */ public function testThrowsExceptionWhenCallingOutsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR EXEC without MULTI'); + $redis = $this->getClient(); $redis->exec(); diff --git a/tests/Predis/Command/Redis/GEOADD_Test.php b/tests/Predis/Command/Redis/GEOADD_Test.php index 58faf8e0..d19cdd76 100644 --- a/tests/Predis/Command/Redis/GEOADD_Test.php +++ b/tests/Predis/Command/Redis/GEOADD_Test.php @@ -93,11 +93,12 @@ class GEOADD_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GEODIST_Test.php b/tests/Predis/Command/Redis/GEODIST_Test.php index 16cdf120..3c60c225 100644 --- a/tests/Predis/Command/Redis/GEODIST_Test.php +++ b/tests/Predis/Command/Redis/GEODIST_Test.php @@ -75,11 +75,12 @@ class GEODIST_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GEOHASH_Test.php b/tests/Predis/Command/Redis/GEOHASH_Test.php index 5fc7bf35..3d489d0b 100644 --- a/tests/Predis/Command/Redis/GEOHASH_Test.php +++ b/tests/Predis/Command/Redis/GEOHASH_Test.php @@ -89,11 +89,12 @@ class GEOHASH_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GEOPOS_Test.php b/tests/Predis/Command/Redis/GEOPOS_Test.php index b554a5bb..59dbf55d 100644 --- a/tests/Predis/Command/Redis/GEOPOS_Test.php +++ b/tests/Predis/Command/Redis/GEOPOS_Test.php @@ -67,13 +67,13 @@ class GEOPOS_Test extends PredisCommandTestCase public function testParseResponse() { $raw = array( - array('13.361389338970184', '38.115556395496299'), - array('15.087267458438873', '37.50266842333162'), + array('13.36138933897018433', '38.11555639549629859'), + array('15.08726745843887329', '37.50266842333162032'), ); $expected = array( - array('13.361389338970184', '38.115556395496299'), - array('15.087267458438873', '37.50266842333162'), + array('13.36138933897018433', '38.11555639549629859'), + array('15.08726745843887329', '37.50266842333162032'), ); $command = $this->getCommand(); @@ -91,19 +91,20 @@ class GEOPOS_Test extends PredisCommandTestCase $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); $this->assertEquals(array( - array('13.361389338970184', '38.115556395496299'), - array('15.087267458438873', '37.50266842333162'), + array('13.36138933897018433', '38.11555639549629859'), + array('15.08726745843887329', '37.50266842333162032'), ), $redis->geopos('Sicily', 'Palermo', 'Catania')); } /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php b/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php index 4a806f16..48aa65fe 100644 --- a/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php +++ b/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php @@ -148,18 +148,19 @@ class GEORADIUSBYMEMBER_Test extends PredisCommandTestCase $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania', '13.583333', '37.316667', 'Agrigento'); $this->assertEquals(array( array('Agrigento', '0.0000', array('13.5833314061164856', '37.31666804993816555')), - array('Palermo', '90.9778', array('13.361389338970184', '38.115556395496299')), + array('Palermo', '90.9778', array('13.36138933897018433', '38.11555639549629859')), ), $redis->georadiusbymember('Sicily', 'Agrigento', 100, 'km', 'WITHDIST', 'WITHCOORD')); } /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GEORADIUS_Test.php b/tests/Predis/Command/Redis/GEORADIUS_Test.php index 18ac4cf8..31801787 100644 --- a/tests/Predis/Command/Redis/GEORADIUS_Test.php +++ b/tests/Predis/Command/Redis/GEORADIUS_Test.php @@ -149,19 +149,20 @@ class GEORADIUS_Test extends PredisCommandTestCase $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); $this->assertEquals(array( - array('Palermo', '190.4424', array('13.361389338970184', '38.115556395496299')), - array('Catania', '56.4413', array('15.087267458438873', '37.50266842333162')), + array('Palermo', '190.4424', array('13.36138933897018433', '38.11555639549629859')), + array('Catania', '56.4413', array('15.08726745843887329', '37.50266842333162032')), ), $redis->georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST', 'WITHCOORD')); } /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/Redis/GETBIT_Test.php b/tests/Predis/Command/Redis/GETBIT_Test.php index 5f290a0f..9b3402cf 100644 --- a/tests/Predis/Command/Redis/GETBIT_Test.php +++ b/tests/Predis/Command/Redis/GETBIT_Test.php @@ -76,11 +76,12 @@ class GETBIT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnNegativeOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('key:binary', "\x80\x00\00\x01"); @@ -90,11 +91,12 @@ class GETBIT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('key:binary', "\x80\x00\00\x01"); @@ -104,11 +106,12 @@ class GETBIT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/GETRANGE_Test.php b/tests/Predis/Command/Redis/GETRANGE_Test.php index 835623fc..ef73fe49 100644 --- a/tests/Predis/Command/Redis/GETRANGE_Test.php +++ b/tests/Predis/Command/Redis/GETRANGE_Test.php @@ -88,11 +88,12 @@ class GETRANGE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.4.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/GETSET_Test.php b/tests/Predis/Command/Redis/GETSET_Test.php index e2fb0595..f67ba260 100644 --- a/tests/Predis/Command/Redis/GETSET_Test.php +++ b/tests/Predis/Command/Redis/GETSET_Test.php @@ -71,11 +71,12 @@ class GETSET_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/GET_Test.php b/tests/Predis/Command/Redis/GET_Test.php index 69eb6f37..ade29278 100644 --- a/tests/Predis/Command/Redis/GET_Test.php +++ b/tests/Predis/Command/Redis/GET_Test.php @@ -92,11 +92,12 @@ class GET_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->rpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/HDEL_Test.php b/tests/Predis/Command/Redis/HDEL_Test.php index 510a28f6..ec04d312 100644 --- a/tests/Predis/Command/Redis/HDEL_Test.php +++ b/tests/Predis/Command/Redis/HDEL_Test.php @@ -87,11 +87,12 @@ class HDEL_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HEXISTS_Test.php b/tests/Predis/Command/Redis/HEXISTS_Test.php index b1b4ebcb..36a769ff 100644 --- a/tests/Predis/Command/Redis/HEXISTS_Test.php +++ b/tests/Predis/Command/Redis/HEXISTS_Test.php @@ -76,11 +76,12 @@ class HEXISTS_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HGETALL_Test.php b/tests/Predis/Command/Redis/HGETALL_Test.php index d17acb67..adc94edc 100644 --- a/tests/Predis/Command/Redis/HGETALL_Test.php +++ b/tests/Predis/Command/Redis/HGETALL_Test.php @@ -77,11 +77,12 @@ class HGETALL_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HGET_Test.php b/tests/Predis/Command/Redis/HGET_Test.php index 09c37ebb..0d0e8136 100644 --- a/tests/Predis/Command/Redis/HGET_Test.php +++ b/tests/Predis/Command/Redis/HGET_Test.php @@ -73,11 +73,12 @@ class HGET_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php b/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php index 8a0e0fed..1c6ade7a 100644 --- a/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php +++ b/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php @@ -90,11 +90,12 @@ class HINCRBYFLOAT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR hash value is not a( valid)? float/ */ public function testThrowsExceptionOnStringField() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR hash value is not a( valid)? float/'); + $redis = $this->getClient(); $redis->hset('metavars', 'foo', 'bar'); @@ -104,11 +105,12 @@ class HINCRBYFLOAT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HINCRBY_Test.php b/tests/Predis/Command/Redis/HINCRBY_Test.php index 754e7296..7fccaad5 100644 --- a/tests/Predis/Command/Redis/HINCRBY_Test.php +++ b/tests/Predis/Command/Redis/HINCRBY_Test.php @@ -86,11 +86,12 @@ class HINCRBY_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR hash value is not an integer */ public function testThrowsExceptionOnStringField() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR hash value is not an integer'); + $redis = $this->getClient(); $redis->hset('metavars', 'foo', 'bar'); @@ -100,11 +101,12 @@ class HINCRBY_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HKEYS_Test.php b/tests/Predis/Command/Redis/HKEYS_Test.php index bd33bde8..6614efb4 100644 --- a/tests/Predis/Command/Redis/HKEYS_Test.php +++ b/tests/Predis/Command/Redis/HKEYS_Test.php @@ -77,11 +77,12 @@ class HKEYS_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HLEN_Test.php b/tests/Predis/Command/Redis/HLEN_Test.php index 6a5c8a37..5210daf8 100644 --- a/tests/Predis/Command/Redis/HLEN_Test.php +++ b/tests/Predis/Command/Redis/HLEN_Test.php @@ -72,11 +72,12 @@ class HLEN_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HMGET_Test.php b/tests/Predis/Command/Redis/HMGET_Test.php index 93a970ec..02d3290e 100644 --- a/tests/Predis/Command/Redis/HMGET_Test.php +++ b/tests/Predis/Command/Redis/HMGET_Test.php @@ -93,11 +93,12 @@ class HMGET_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/HMSET_Test.php b/tests/Predis/Command/Redis/HMSET_Test.php index d79136a5..58cbce3b 100644 --- a/tests/Predis/Command/Redis/HMSET_Test.php +++ b/tests/Predis/Command/Redis/HMSET_Test.php @@ -100,11 +100,12 @@ class HMSET_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'bar'); diff --git a/tests/Predis/Command/Redis/HSETNX_Test.php b/tests/Predis/Command/Redis/HSETNX_Test.php index 3bc9324b..db32fbe0 100644 --- a/tests/Predis/Command/Redis/HSETNX_Test.php +++ b/tests/Predis/Command/Redis/HSETNX_Test.php @@ -76,11 +76,12 @@ class HSETNX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/HSET_Test.php b/tests/Predis/Command/Redis/HSET_Test.php index 0db2e1e3..e7a9e782 100644 --- a/tests/Predis/Command/Redis/HSET_Test.php +++ b/tests/Predis/Command/Redis/HSET_Test.php @@ -75,11 +75,12 @@ class HSET_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/HSTRLEN_Test.php b/tests/Predis/Command/Redis/HSTRLEN_Test.php index 42522b2f..5c4b3601 100644 --- a/tests/Predis/Command/Redis/HSTRLEN_Test.php +++ b/tests/Predis/Command/Redis/HSTRLEN_Test.php @@ -83,11 +83,12 @@ class HSTRLEN_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/HVALS_Test.php b/tests/Predis/Command/Redis/HVALS_Test.php index 5c67b479..ff3d649f 100644 --- a/tests/Predis/Command/Redis/HVALS_Test.php +++ b/tests/Predis/Command/Redis/HVALS_Test.php @@ -77,11 +77,12 @@ class HVALS_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php b/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php index 2d3d2b48..3e409e65 100644 --- a/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php +++ b/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php @@ -87,11 +87,12 @@ class INCRBYFLOAT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not a valid float */ public function testThrowsExceptionOnDecrementValueNotFloat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not a valid float'); + $redis = $this->getClient(); $redis->incrbyfloat('foo', 'bar'); @@ -100,11 +101,12 @@ class INCRBYFLOAT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not a valid float */ public function testThrowsExceptionOnKeyValueNotFloat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not a valid float'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -114,11 +116,12 @@ class INCRBYFLOAT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/INCRBY_Test.php b/tests/Predis/Command/Redis/INCRBY_Test.php index 50b43dc0..61e1ff83 100644 --- a/tests/Predis/Command/Redis/INCRBY_Test.php +++ b/tests/Predis/Command/Redis/INCRBY_Test.php @@ -82,11 +82,12 @@ class INCRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnDecrementValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->incrby('foo', 'bar'); @@ -94,11 +95,12 @@ class INCRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -107,11 +109,12 @@ class INCRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/INCR_Test.php b/tests/Predis/Command/Redis/INCR_Test.php index 5c79edfc..7cbda723 100644 --- a/tests/Predis/Command/Redis/INCR_Test.php +++ b/tests/Predis/Command/Redis/INCR_Test.php @@ -81,11 +81,12 @@ class INCR_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/INFO_Test.php b/tests/Predis/Command/Redis/INFO_Test.php index 09291dbe..5105789b 100644 --- a/tests/Predis/Command/Redis/INFO_Test.php +++ b/tests/Predis/Command/Redis/INFO_Test.php @@ -308,7 +308,7 @@ BUFFER; $redis = $this->getClient(); $command = $this->getCommand(); - $this->assertInternalType('array', $info = $redis->executeCommand($command)); + $this->assertIsArray($info = $redis->executeCommand($command)); $this->assertArrayHasKey('redis_version', isset($info['Server']) ? $info['Server'] : $info); } /** diff --git a/tests/Predis/Command/Redis/LASTSAVE_Test.php b/tests/Predis/Command/Redis/LASTSAVE_Test.php index 7189e268..3ad9980e 100644 --- a/tests/Predis/Command/Redis/LASTSAVE_Test.php +++ b/tests/Predis/Command/Redis/LASTSAVE_Test.php @@ -59,6 +59,6 @@ class LASTSAVE_Test extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('integer', $redis->lastsave()); + $this->assertIsInt($redis->lastsave()); } } diff --git a/tests/Predis/Command/Redis/LINDEX_Test.php b/tests/Predis/Command/Redis/LINDEX_Test.php index a91cfb49..3a720531 100644 --- a/tests/Predis/Command/Redis/LINDEX_Test.php +++ b/tests/Predis/Command/Redis/LINDEX_Test.php @@ -86,11 +86,12 @@ class LINDEX_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/LINSERT_Test.php b/tests/Predis/Command/Redis/LINSERT_Test.php index 61429893..f399606f 100644 --- a/tests/Predis/Command/Redis/LINSERT_Test.php +++ b/tests/Predis/Command/Redis/LINSERT_Test.php @@ -94,11 +94,12 @@ class LINSERT_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/LLEN_Test.php b/tests/Predis/Command/Redis/LLEN_Test.php index e00be70c..72a20b38 100644 --- a/tests/Predis/Command/Redis/LLEN_Test.php +++ b/tests/Predis/Command/Redis/LLEN_Test.php @@ -84,11 +84,12 @@ class LLEN_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/LPOP_Test.php b/tests/Predis/Command/Redis/LPOP_Test.php index 7f42eb9c..8f76b355 100644 --- a/tests/Predis/Command/Redis/LPOP_Test.php +++ b/tests/Predis/Command/Redis/LPOP_Test.php @@ -81,11 +81,12 @@ class LPOP_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/LPUSHX_Test.php b/tests/Predis/Command/Redis/LPUSHX_Test.php index da0d4859..f34c960e 100644 --- a/tests/Predis/Command/Redis/LPUSHX_Test.php +++ b/tests/Predis/Command/Redis/LPUSHX_Test.php @@ -85,11 +85,12 @@ class LPUSHX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/LPUSH_Test.php b/tests/Predis/Command/Redis/LPUSH_Test.php index c63d71b4..0c1fe9d1 100644 --- a/tests/Predis/Command/Redis/LPUSH_Test.php +++ b/tests/Predis/Command/Redis/LPUSH_Test.php @@ -84,11 +84,12 @@ class LPUSH_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/LRANGE_Test.php b/tests/Predis/Command/Redis/LRANGE_Test.php index d89f5e4f..c54bb9c1 100644 --- a/tests/Predis/Command/Redis/LRANGE_Test.php +++ b/tests/Predis/Command/Redis/LRANGE_Test.php @@ -125,11 +125,12 @@ class LRANGE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/LREM_Test.php b/tests/Predis/Command/Redis/LREM_Test.php index 3667feb6..d3d6b54c 100644 --- a/tests/Predis/Command/Redis/LREM_Test.php +++ b/tests/Predis/Command/Redis/LREM_Test.php @@ -109,11 +109,12 @@ class LREM_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/LSET_Test.php b/tests/Predis/Command/Redis/LSET_Test.php index c5c0bd75..a3b2f2ca 100644 --- a/tests/Predis/Command/Redis/LSET_Test.php +++ b/tests/Predis/Command/Redis/LSET_Test.php @@ -70,11 +70,12 @@ class LSET_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR index out of range */ public function testThrowsExceptionOnIndexOutOfRange() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR index out of range'); + $redis = $this->getClient(); $redis->rpush('letters', 'a', 'b', 'c'); @@ -83,11 +84,12 @@ class LSET_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/LTRIM_Test.php b/tests/Predis/Command/Redis/LTRIM_Test.php index 53b887d0..1fdf9c04 100644 --- a/tests/Predis/Command/Redis/LTRIM_Test.php +++ b/tests/Predis/Command/Redis/LTRIM_Test.php @@ -115,11 +115,12 @@ class LTRIM_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/MIGRATE_Test.php b/tests/Predis/Command/Redis/MIGRATE_Test.php index 5b6e203a..d5cf8756 100644 --- a/tests/Predis/Command/Redis/MIGRATE_Test.php +++ b/tests/Predis/Command/Redis/MIGRATE_Test.php @@ -101,11 +101,12 @@ class MIGRATE_Test extends PredisCommandTestCase * @group connected * @requiresRedisVersion >= 2.6.0 * @group slow - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage IOERR */ public function testReturnsErrorOnUnreacheableDestination() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('IOERR'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/MOVE_Test.php b/tests/Predis/Command/Redis/MOVE_Test.php index 927ca6ac..f17e5bd1 100644 --- a/tests/Predis/Command/Redis/MOVE_Test.php +++ b/tests/Predis/Command/Redis/MOVE_Test.php @@ -81,11 +81,12 @@ class MOVE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR index out of range */ public function testThrowsExceptionOnInvalidDatabases() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR index out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/MULTI_Test.php b/tests/Predis/Command/Redis/MULTI_Test.php index 816c799e..ca730eb1 100644 --- a/tests/Predis/Command/Redis/MULTI_Test.php +++ b/tests/Predis/Command/Redis/MULTI_Test.php @@ -78,11 +78,12 @@ class MULTI_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR MULTI calls can not be nested */ public function testThrowsExceptionWhenCallingMultiInsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR MULTI calls can not be nested'); + $redis = $this->getClient(); $redis->multi(); diff --git a/tests/Predis/Command/Redis/OBJECT_Test.php b/tests/Predis/Command/Redis/OBJECT_Test.php index 6e445ecb..6aeac809 100644 --- a/tests/Predis/Command/Redis/OBJECT_Test.php +++ b/tests/Predis/Command/Redis/OBJECT_Test.php @@ -64,7 +64,7 @@ class OBJECT_Test extends PredisCommandTestCase $redis = $this->getClient(); $redis->set('foo', 'bar'); - $this->assertInternalType('integer', $redis->object('REFCOUNT', 'foo')); + $this->assertIsInt($redis->object('REFCOUNT', 'foo')); } /** @@ -76,7 +76,7 @@ class OBJECT_Test extends PredisCommandTestCase $redis = $this->getClient(); $redis->set('foo', 'bar'); - $this->assertInternalType('integer', $redis->object('IDLETIME', 'foo')); + $this->assertIsInt($redis->object('IDLETIME', 'foo')); } /** @@ -107,10 +107,11 @@ class OBJECT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.3 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->object('INVALID', 'foo'); diff --git a/tests/Predis/Command/Redis/PFADD_Test.php b/tests/Predis/Command/Redis/PFADD_Test.php index ca064774..b6630b93 100644 --- a/tests/Predis/Command/Redis/PFADD_Test.php +++ b/tests/Predis/Command/Redis/PFADD_Test.php @@ -77,11 +77,12 @@ class PFADD_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo', 'hoge'); diff --git a/tests/Predis/Command/Redis/PFCOUNT_Test.php b/tests/Predis/Command/Redis/PFCOUNT_Test.php index 8bd8f9f5..fb4791b9 100644 --- a/tests/Predis/Command/Redis/PFCOUNT_Test.php +++ b/tests/Predis/Command/Redis/PFCOUNT_Test.php @@ -78,11 +78,12 @@ class PFCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo', 'hoge'); @@ -92,11 +93,12 @@ class PFCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfAtLeastOneKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->pfadd('metavars:1', 'foo', 'hoge'); diff --git a/tests/Predis/Command/Redis/PFMERGE_Test.php b/tests/Predis/Command/Redis/PFMERGE_Test.php index 5797490f..db60f6be 100644 --- a/tests/Predis/Command/Redis/PFMERGE_Test.php +++ b/tests/Predis/Command/Redis/PFMERGE_Test.php @@ -74,11 +74,12 @@ class PFMERGE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->pfadd('metavars:1', 'foo', 'hoge'); diff --git a/tests/Predis/Command/Redis/PSETEX_Test.php b/tests/Predis/Command/Redis/PSETEX_Test.php index 0e959625..46008415 100644 --- a/tests/Predis/Command/Redis/PSETEX_Test.php +++ b/tests/Predis/Command/Redis/PSETEX_Test.php @@ -86,33 +86,36 @@ class PSETEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnNonIntegerTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $this->getClient()->psetex('foo', 2.5, 'bar'); } /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnZeroTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->psetex('foo', 0, 'bar'); } /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnNegativeTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->psetex('foo', -10000, 'bar'); } } diff --git a/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php b/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php index 788becdf..fe2f1bde 100644 --- a/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php @@ -151,11 +151,12 @@ class PSUBSCRIBE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/ */ public function testCannotSendOtherCommandsAfterPsubscribe() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*only .* allowed in this context/'); + $redis = $this->getClient(); $redis->psubscribe('channel:*'); diff --git a/tests/Predis/Command/Redis/RENAMENX_Test.php b/tests/Predis/Command/Redis/RENAMENX_Test.php index b75cfa51..826521b3 100644 --- a/tests/Predis/Command/Redis/RENAMENX_Test.php +++ b/tests/Predis/Command/Redis/RENAMENX_Test.php @@ -72,11 +72,12 @@ class RENAMENX_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR no such key */ public function testThrowsExceptionWhenRenamingNonExistingKeys() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR no such key'); + $redis = $this->getClient(); $this->assertSame(0, $redis->renamenx('foo', 'foobar')); diff --git a/tests/Predis/Command/Redis/RENAME_Test.php b/tests/Predis/Command/Redis/RENAME_Test.php index 7c99207a..03e53eb2 100644 --- a/tests/Predis/Command/Redis/RENAME_Test.php +++ b/tests/Predis/Command/Redis/RENAME_Test.php @@ -71,11 +71,12 @@ class RENAME_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR no such key */ public function testThrowsExceptionOnNonExistingKeys() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR no such key'); + $redis = $this->getClient(); $redis->rename('foo', 'foobar'); diff --git a/tests/Predis/Command/Redis/RPOPLPUSH_Test.php b/tests/Predis/Command/Redis/RPOPLPUSH_Test.php index 55eda285..b60f14a7 100644 --- a/tests/Predis/Command/Redis/RPOPLPUSH_Test.php +++ b/tests/Predis/Command/Redis/RPOPLPUSH_Test.php @@ -100,11 +100,12 @@ class RPOPLPUSH_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('key:source', 'foo'); @@ -113,11 +114,12 @@ class RPOPLPUSH_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfDestinationKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->rpush('key:source', 'foo'); diff --git a/tests/Predis/Command/Redis/RPOP_Test.php b/tests/Predis/Command/Redis/RPOP_Test.php index be388fc0..793a5ff1 100644 --- a/tests/Predis/Command/Redis/RPOP_Test.php +++ b/tests/Predis/Command/Redis/RPOP_Test.php @@ -81,11 +81,12 @@ class RPOP_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/RPUSHX_Test.php b/tests/Predis/Command/Redis/RPUSHX_Test.php index b7eb4302..0ae9d17d 100644 --- a/tests/Predis/Command/Redis/RPUSHX_Test.php +++ b/tests/Predis/Command/Redis/RPUSHX_Test.php @@ -85,11 +85,12 @@ class RPUSHX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/RPUSH_Test.php b/tests/Predis/Command/Redis/RPUSH_Test.php index 9c9895bd..b3bd8855 100644 --- a/tests/Predis/Command/Redis/RPUSH_Test.php +++ b/tests/Predis/Command/Redis/RPUSH_Test.php @@ -84,11 +84,12 @@ class RPUSH_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SADD_Test.php b/tests/Predis/Command/Redis/SADD_Test.php index 146fde42..f106bb20 100644 --- a/tests/Predis/Command/Redis/SADD_Test.php +++ b/tests/Predis/Command/Redis/SADD_Test.php @@ -85,7 +85,7 @@ class SADD_Test extends PredisCommandTestCase * @group connected * @requiresRedisVersion >= 2.4.0 */ - public function testAddsMembersToSetVariadic() + public function c() { $redis = $this->getClient(); @@ -94,11 +94,12 @@ class SADD_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SCARD_Test.php b/tests/Predis/Command/Redis/SCARD_Test.php index 2f71908e..4534609a 100644 --- a/tests/Predis/Command/Redis/SCARD_Test.php +++ b/tests/Predis/Command/Redis/SCARD_Test.php @@ -79,11 +79,12 @@ class SCARD_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SCRIPT_Test.php b/tests/Predis/Command/Redis/SCRIPT_Test.php index fdb4a2cc..573ca777 100644 --- a/tests/Predis/Command/Redis/SCRIPT_Test.php +++ b/tests/Predis/Command/Redis/SCRIPT_Test.php @@ -100,10 +100,11 @@ class SCRIPT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.6.0 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->script('INVALID'); diff --git a/tests/Predis/Command/Redis/SDIFFSTORE_Test.php b/tests/Predis/Command/Redis/SDIFFSTORE_Test.php index 41ef9a37..45823343 100644 --- a/tests/Predis/Command/Redis/SDIFFSTORE_Test.php +++ b/tests/Predis/Command/Redis/SDIFFSTORE_Test.php @@ -102,11 +102,12 @@ class SDIFFSTORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/Redis/SDIFF_Test.php b/tests/Predis/Command/Redis/SDIFF_Test.php index e4af208b..1881fe15 100644 --- a/tests/Predis/Command/Redis/SDIFF_Test.php +++ b/tests/Predis/Command/Redis/SDIFF_Test.php @@ -104,11 +104,12 @@ class SDIFF_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/Redis/SELECT_Test.php b/tests/Predis/Command/Redis/SELECT_Test.php index d6f8ec1d..ca7ca24c 100644 --- a/tests/Predis/Command/Redis/SELECT_Test.php +++ b/tests/Predis/Command/Redis/SELECT_Test.php @@ -70,11 +70,12 @@ class SELECT_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*DB index/ */ public function testThrowsExceptionOnUnexpectedDatabaseRange() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*DB index/'); + $redis = $this->getClient(); $redis->select(100000000); @@ -82,11 +83,12 @@ class SELECT_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid DB index */ public function testThrowsExceptionOnUnexpectedDatabaseName() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid DB index'); + $redis = $this->getClient(); $redis->select('x'); diff --git a/tests/Predis/Command/Redis/SETBIT_Test.php b/tests/Predis/Command/Redis/SETBIT_Test.php index 16f00877..fe046907 100644 --- a/tests/Predis/Command/Redis/SETBIT_Test.php +++ b/tests/Predis/Command/Redis/SETBIT_Test.php @@ -89,44 +89,48 @@ class SETBIT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit is not an integer or out of range */ public function testThrowsExceptionOnInvalidBitValue() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit is not an integer or out of range'); + $this->getClient()->setbit('key:binary', 10, 255); } /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnNegativeOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $this->getClient()->setbit('key:binary', -1, 1); } /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $this->getClient()->setbit('key:binary', 'invalid', 1); } /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SETEX_Test.php b/tests/Predis/Command/Redis/SETEX_Test.php index 85781e90..2f7d7301 100644 --- a/tests/Predis/Command/Redis/SETEX_Test.php +++ b/tests/Predis/Command/Redis/SETEX_Test.php @@ -87,33 +87,36 @@ class SETEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnNonIntegerTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $this->getClient()->setex('foo', 2.5, 'bar'); } /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnZeroTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->setex('foo', 0, 'bar'); } /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnNegativeTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->setex('foo', -10, 'bar'); } } diff --git a/tests/Predis/Command/Redis/SETRANGE_Test.php b/tests/Predis/Command/Redis/SETRANGE_Test.php index f102bccd..551ac229 100644 --- a/tests/Predis/Command/Redis/SETRANGE_Test.php +++ b/tests/Predis/Command/Redis/SETRANGE_Test.php @@ -104,22 +104,24 @@ class SETRANGE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR offset is out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR offset is out of range'); + $this->getClient()->setrange('var', -1, 'bogus'); } /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SINTERSTORE_Test.php b/tests/Predis/Command/Redis/SINTERSTORE_Test.php index 6612fbad..c94a49f4 100644 --- a/tests/Predis/Command/Redis/SINTERSTORE_Test.php +++ b/tests/Predis/Command/Redis/SINTERSTORE_Test.php @@ -115,11 +115,12 @@ class SINTERSTORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/Redis/SINTER_Test.php b/tests/Predis/Command/Redis/SINTER_Test.php index a39ef323..5915aef5 100644 --- a/tests/Predis/Command/Redis/SINTER_Test.php +++ b/tests/Predis/Command/Redis/SINTER_Test.php @@ -115,11 +115,12 @@ class SINTER_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/Redis/SISMEMBER_Test.php b/tests/Predis/Command/Redis/SISMEMBER_Test.php index c85a319e..697757af 100644 --- a/tests/Predis/Command/Redis/SISMEMBER_Test.php +++ b/tests/Predis/Command/Redis/SISMEMBER_Test.php @@ -83,11 +83,12 @@ class SISMEMBER_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/SLOWLOG_Test.php b/tests/Predis/Command/Redis/SLOWLOG_Test.php index 89bcd6d9..f112984d 100644 --- a/tests/Predis/Command/Redis/SLOWLOG_Test.php +++ b/tests/Predis/Command/Redis/SLOWLOG_Test.php @@ -98,14 +98,14 @@ class SLOWLOG_Test extends PredisCommandTestCase $redis->config('set', 'slowlog-log-slower-than', 0); $redis->set('foo', 'bar'); - $this->assertInternalType('array', $slowlog = $redis->slowlog('GET')); + $this->assertIsArray($slowlog = $redis->slowlog('GET')); $this->assertGreaterThan(0, count($slowlog)); - $this->assertInternalType('array', $slowlog[0]); + $this->assertIsArray($slowlog[0]); $this->assertGreaterThan(0, $slowlog[0]['id']); $this->assertGreaterThan(0, $slowlog[0]['timestamp']); $this->assertGreaterThan(0, $slowlog[0]['duration']); - $this->assertInternalType('array', $slowlog[0]['command']); + $this->assertIsArray($slowlog[0]['command']); $redis->config('set', 'slowlog-log-slower-than', $threshold); } @@ -124,10 +124,11 @@ class SLOWLOG_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.12 - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->slowlog('INVALID'); diff --git a/tests/Predis/Command/Redis/SMEMBERS_Test.php b/tests/Predis/Command/Redis/SMEMBERS_Test.php index c57098bf..8d2584f8 100644 --- a/tests/Predis/Command/Redis/SMEMBERS_Test.php +++ b/tests/Predis/Command/Redis/SMEMBERS_Test.php @@ -75,11 +75,12 @@ class SMEMBERS_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/SMOVE_Test.php b/tests/Predis/Command/Redis/SMOVE_Test.php index 27f032ef..87f44b2f 100644 --- a/tests/Predis/Command/Redis/SMOVE_Test.php +++ b/tests/Predis/Command/Redis/SMOVE_Test.php @@ -76,11 +76,12 @@ class SMOVE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); @@ -90,11 +91,12 @@ class SMOVE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfDestinationKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->sadd('set:source', 'foo'); diff --git a/tests/Predis/Command/Redis/SORT_Test.php b/tests/Predis/Command/Redis/SORT_Test.php index 27041c01..ffa38124 100644 --- a/tests/Predis/Command/Redis/SORT_Test.php +++ b/tests/Predis/Command/Redis/SORT_Test.php @@ -232,11 +232,12 @@ class SORT_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/SPOP_Test.php b/tests/Predis/Command/Redis/SPOP_Test.php index 16b5cac0..4a3d54d6 100644 --- a/tests/Predis/Command/Redis/SPOP_Test.php +++ b/tests/Predis/Command/Redis/SPOP_Test.php @@ -88,11 +88,12 @@ class SPOP_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/SRANDMEMBER_Test.php b/tests/Predis/Command/Redis/SRANDMEMBER_Test.php index c11d67e9..a402592d 100644 --- a/tests/Predis/Command/Redis/SRANDMEMBER_Test.php +++ b/tests/Predis/Command/Redis/SRANDMEMBER_Test.php @@ -80,11 +80,12 @@ class SRANDMEMBER_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/SREM_Test.php b/tests/Predis/Command/Redis/SREM_Test.php index 13c1f202..2d0ee94e 100644 --- a/tests/Predis/Command/Redis/SREM_Test.php +++ b/tests/Predis/Command/Redis/SREM_Test.php @@ -103,11 +103,12 @@ class SREM_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/STRLEN_Test.php b/tests/Predis/Command/Redis/STRLEN_Test.php index d10620d4..8c49a436 100644 --- a/tests/Predis/Command/Redis/STRLEN_Test.php +++ b/tests/Predis/Command/Redis/STRLEN_Test.php @@ -84,11 +84,12 @@ class STRLEN_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/Redis/SUBSCRIBE_Test.php b/tests/Predis/Command/Redis/SUBSCRIBE_Test.php index 1d2f2b5f..14421ac9 100644 --- a/tests/Predis/Command/Redis/SUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/SUBSCRIBE_Test.php @@ -151,11 +151,12 @@ class SUBSCRIBE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/ */ public function testCannotSendOtherCommandsAfterSubscribe() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*only .* allowed in this context/'); + $redis = $this->getClient(); $redis->subscribe('channel:foo'); diff --git a/tests/Predis/Command/Redis/SUNIONSTORE_Test.php b/tests/Predis/Command/Redis/SUNIONSTORE_Test.php index bf9fad3d..bcb86f60 100644 --- a/tests/Predis/Command/Redis/SUNIONSTORE_Test.php +++ b/tests/Predis/Command/Redis/SUNIONSTORE_Test.php @@ -102,11 +102,12 @@ class SUNIONSTORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/Redis/SUNION_Test.php b/tests/Predis/Command/Redis/SUNION_Test.php index 2f089b14..dd98a949 100644 --- a/tests/Predis/Command/Redis/SUNION_Test.php +++ b/tests/Predis/Command/Redis/SUNION_Test.php @@ -104,11 +104,12 @@ class SUNION_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/Redis/TIME_Test.php b/tests/Predis/Command/Redis/TIME_Test.php index db8c91bb..21fb41a7 100644 --- a/tests/Predis/Command/Redis/TIME_Test.php +++ b/tests/Predis/Command/Redis/TIME_Test.php @@ -66,8 +66,8 @@ class TIME_Test extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $time = $redis->time()); - $this->assertInternalType('string', $time[0]); - $this->assertInternalType('string', $time[1]); + $this->assertIsArray($time = $redis->time()); + $this->assertIsString($time[0]); + $this->assertIsString($time[1]); } } diff --git a/tests/Predis/Command/Redis/WATCH_Test.php b/tests/Predis/Command/Redis/WATCH_Test.php index 3ff80e5f..1941f687 100644 --- a/tests/Predis/Command/Redis/WATCH_Test.php +++ b/tests/Predis/Command/Redis/WATCH_Test.php @@ -108,11 +108,12 @@ class WATCH_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR WATCH inside MULTI is not allowed */ public function testThrowsExceptionWhenCallingInsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR WATCH inside MULTI is not allowed'); + $redis = $this->getClient(); $redis->multi(); diff --git a/tests/Predis/Command/Redis/ZADD_Test.php b/tests/Predis/Command/Redis/ZADD_Test.php index b6eb4380..6fbb7d35 100644 --- a/tests/Predis/Command/Redis/ZADD_Test.php +++ b/tests/Predis/Command/Redis/ZADD_Test.php @@ -162,11 +162,12 @@ class ZADD_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.0.2 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage INCR option supports a single increment-element pair */ public function testDoesNotAcceptMultipleScoreElementPairsWithModifierINCR() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('INCR option supports a single increment-element pair'); + $redis = $this->getClient(); $redis->zadd('letters', 'INCR', 1, 'a', 2, 'b'); @@ -185,11 +186,12 @@ class ZADD_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZCARD_Test.php b/tests/Predis/Command/Redis/ZCARD_Test.php index f168cf03..59ae162b 100644 --- a/tests/Predis/Command/Redis/ZCARD_Test.php +++ b/tests/Predis/Command/Redis/ZCARD_Test.php @@ -70,11 +70,12 @@ class ZCARD_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZCOUNT_Test.php b/tests/Predis/Command/Redis/ZCOUNT_Test.php index 138a7512..b9e56684 100644 --- a/tests/Predis/Command/Redis/ZCOUNT_Test.php +++ b/tests/Predis/Command/Redis/ZCOUNT_Test.php @@ -107,11 +107,12 @@ class ZCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZINCRBY_Test.php b/tests/Predis/Command/Redis/ZINCRBY_Test.php index 0498323c..e38e0481 100644 --- a/tests/Predis/Command/Redis/ZINCRBY_Test.php +++ b/tests/Predis/Command/Redis/ZINCRBY_Test.php @@ -70,11 +70,12 @@ class ZINCRBY_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php index 5a006da7..5ad3f096 100644 --- a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php @@ -161,11 +161,12 @@ class ZINTERSTORE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php b/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php index c89ce106..9f525ee4 100644 --- a/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php +++ b/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php @@ -104,11 +104,12 @@ class ZLEXCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -118,11 +119,12 @@ class ZLEXCOUNT_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php index 8b407824..e9c02c1d 100644 --- a/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php @@ -167,11 +167,12 @@ class ZRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -181,11 +182,12 @@ class ZRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php index de0361cc..83cb2b55 100644 --- a/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php @@ -214,11 +214,12 @@ class ZRANGEBYSCORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZRANGE_Test.php b/tests/Predis/Command/Redis/ZRANGE_Test.php index bc2f03c0..6b293472 100644 --- a/tests/Predis/Command/Redis/ZRANGE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGE_Test.php @@ -142,11 +142,12 @@ class ZRANGE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZRANK_Test.php b/tests/Predis/Command/Redis/ZRANK_Test.php index 4a183274..9262ba20 100644 --- a/tests/Predis/Command/Redis/ZRANK_Test.php +++ b/tests/Predis/Command/Redis/ZRANK_Test.php @@ -75,11 +75,12 @@ class ZRANK_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php index 0fab428c..785cd798 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php @@ -116,11 +116,12 @@ class ZREMRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -130,11 +131,12 @@ class ZREMRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php index d618a243..a1a59425 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php @@ -88,11 +88,12 @@ class ZREMRANGEBYRANK_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php index c1273268..6642a769 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php @@ -85,11 +85,12 @@ class ZREMRANGEBYSCORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREM_Test.php b/tests/Predis/Command/Redis/ZREM_Test.php index 41c479c0..6b21d4c9 100644 --- a/tests/Predis/Command/Redis/ZREM_Test.php +++ b/tests/Predis/Command/Redis/ZREM_Test.php @@ -72,11 +72,12 @@ class ZREM_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php index a5af1c56..edefa419 100644 --- a/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php @@ -167,11 +167,12 @@ class ZREVRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -181,11 +182,12 @@ class ZREVRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php index 778cd844..e3e9727c 100644 --- a/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php @@ -221,11 +221,12 @@ class ZREVRANGEBYSCORE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREVRANGE_Test.php b/tests/Predis/Command/Redis/ZREVRANGE_Test.php index 7ad88bf5..4e91203c 100644 --- a/tests/Predis/Command/Redis/ZREVRANGE_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGE_Test.php @@ -142,11 +142,12 @@ class ZREVRANGE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZREVRANK_Test.php b/tests/Predis/Command/Redis/ZREVRANK_Test.php index 729e938d..4677cf98 100644 --- a/tests/Predis/Command/Redis/ZREVRANK_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANK_Test.php @@ -75,11 +75,12 @@ class ZREVRANK_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZSCORE_Test.php b/tests/Predis/Command/Redis/ZSCORE_Test.php index 1c5af71e..f17aecf3 100644 --- a/tests/Predis/Command/Redis/ZSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZSCORE_Test.php @@ -73,11 +73,12 @@ class ZSCORE_Test extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php index c9a9dbb9..70f863f3 100644 --- a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php @@ -179,11 +179,12 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.0.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/RedisFactoryTest.php b/tests/Predis/Command/RedisFactoryTest.php index 23705550..db3f9641 100644 --- a/tests/Predis/Command/RedisFactoryTest.php +++ b/tests/Predis/Command/RedisFactoryTest.php @@ -81,7 +81,9 @@ class RedisFactoryTest extends PredisTestCase { $factory = new RedisFactory(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface') + ->getMock(); + $factory->defineCommand('mock', get_class($command)); $this->assertTrue($factory->supportsCommand('mock')); @@ -113,7 +115,7 @@ class RedisFactoryTest extends PredisTestCase { $factory = new RedisFactory(); - $commandClass = get_class($this->getMock('Predis\Command\CommandInterface')); + $commandClass = get_class($this->getMockBuilder('Predis\Command\CommandInterface')->getMock()); $factory->defineCommand('MOCK', $commandClass); $this->assertTrue($factory->supportsCommand('MOCK')); @@ -127,11 +129,12 @@ class RedisFactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The class 'stdClass' is not a valid command class. */ public function testDefineInvalidCommand() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("The class 'stdClass' is not a valid command class."); + $factory = new RedisFactory(); $factory->defineCommand('mock', 'stdClass'); @@ -168,11 +171,12 @@ class RedisFactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Command 'UNKNOWN' is not a registered Redis command. */ public function testCreateUndefinedCommand() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("Command 'UNKNOWN' is not a registered Redis command."); + $factory = new RedisFactory(); $factory->createCommand('unknown'); @@ -193,7 +197,8 @@ class RedisFactoryTest extends PredisTestCase */ public function testSetProcessor() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface') + ->getMock(); $factory = new RedisFactory(); $factory->setProcessor($processor); @@ -206,7 +211,9 @@ class RedisFactoryTest extends PredisTestCase */ public function testSetAndUnsetProcessor() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface') + ->getMock(); + $factory = new RedisFactory(); $factory->setProcessor($processor); @@ -225,7 +232,8 @@ class RedisFactoryTest extends PredisTestCase // method are cloned instead of being passed by reference? $argsRef = null; - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface') + ->getMock(); $processor ->expects($this->once()) ->method('process') @@ -248,7 +256,8 @@ class RedisFactoryTest extends PredisTestCase */ public function testChainOfProcessors() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface') + ->getMock(); $processor ->expects($this->exactly(2)) ->method('process'); diff --git a/tests/Predis/Command/ScriptCommandTest.php b/tests/Predis/Command/ScriptCommandTest.php index 7b95a8a0..0e8c6481 100644 --- a/tests/Predis/Command/ScriptCommandTest.php +++ b/tests/Predis/Command/ScriptCommandTest.php @@ -26,7 +26,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetId() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript')) + ->getMock(); $this->assertSame('EVALSHA', $command->getId()); } @@ -36,7 +38,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetScriptHash() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->exactly(2)) ->method('getScript') @@ -56,7 +60,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetKeys() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -76,7 +82,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetKeysWithZeroKeysCount() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -92,7 +100,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetKeysWithNegativeKeysCount() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -112,7 +122,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetArguments() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -132,7 +144,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetArgumentsWithZeroKeysCount() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -148,7 +162,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetArgumentsWithNegativeKeysCount() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->once()) ->method('getScript') @@ -168,7 +184,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetEvalArguments() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->exactly(2)) ->method('getScript') @@ -188,7 +206,9 @@ class ScriptCommandTest extends PredisTestCase */ public function testGetEvalCommand() { - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command ->expects($this->exactly(2)) ->method('getScript') diff --git a/tests/Predis/CommunicationExceptionTest.php b/tests/Predis/CommunicationExceptionTest.php index 1b2967ff..6c5cddcf 100644 --- a/tests/Predis/CommunicationExceptionTest.php +++ b/tests/Predis/CommunicationExceptionTest.php @@ -31,13 +31,14 @@ class CommunicationExceptionTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\CommunicationException - * @expectedExceptionMessage Connection error message */ public function testExceptionMessage() { $connection = $this->getMockConnection(); - $exception = $this->createMockException($connection, 'Connection error message'); + $exception = $this->createMockException($connection, $message = 'Connection error message'); + + $this->expectException('Predis\CommunicationException'); + $this->expectExceptionMessage($message); throw $exception; } @@ -55,8 +56,6 @@ class CommunicationExceptionTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\CommunicationException - * @expectedExceptionMessage Communication error message */ public function testCommunicationExceptionHandling() { @@ -69,15 +68,16 @@ class CommunicationExceptionTest extends PredisTestCase ->expects($this->once()) ->method('disconnect'); - $exception = $this->createMockException($connection, 'Communication error message'); + $exception = $this->createMockException($connection, $message = 'Communication error message'); + + $this->expectException('Predis\CommunicationException'); + $this->expectExceptionMessage($message); CommunicationException::handle($exception); } /** * @group disconnected - * @expectedException \Predis\CommunicationException - * @expectedExceptionMessage Communication error message */ public function testCommunicationExceptionHandlingWhenShouldResetConnectionIsFalse() { @@ -98,6 +98,9 @@ class CommunicationExceptionTest extends PredisTestCase ->method('shouldResetConnection') ->will($this->returnValue(false)); + $this->expectException('Predis\CommunicationException'); + $this->expectExceptionMessage('Communication error message'); + CommunicationException::handle($exception); } diff --git a/tests/Predis/Configuration/Option/AggregateTest.php b/tests/Predis/Configuration/Option/AggregateTest.php index 7c84e665..060be5cd 100644 --- a/tests/Predis/Configuration/Option/AggregateTest.php +++ b/tests/Predis/Configuration/Option/AggregateTest.php @@ -25,7 +25,7 @@ class AggregateTest extends PredisTestCase { $option = new Aggregate(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertNull($option->getDefault($options)); } @@ -37,10 +37,12 @@ class AggregateTest extends PredisTestCase { $option = new Aggregate(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -53,17 +55,20 @@ class AggregateTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid connection type returned by callable initializer */ public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Aggregate expects a valid connection type returned by callable initializer'); + $option = new Aggregate(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -77,15 +82,16 @@ class AggregateTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid callable */ public function testThrowsExceptionOnInstanceOfAggregateConnectionInterface() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Aggregate expects a valid callable'); + $option = new Aggregate(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $cluster = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $cluster = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); $option->filter($options, $cluster); } diff --git a/tests/Predis/Configuration/Option/CRC16Test.php b/tests/Predis/Configuration/Option/CRC16Test.php index d81cb2ef..669d6368 100644 --- a/tests/Predis/Configuration/Option/CRC16Test.php +++ b/tests/Predis/Configuration/Option/CRC16Test.php @@ -26,7 +26,7 @@ class CRC16Test extends PredisTestCase { $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $hashGenerator = $option->getDefault($options); $this->assertInstanceOf('Predis\Cluster\Hash\HashGeneratorInterface', $hashGenerator); @@ -45,8 +45,8 @@ class CRC16Test extends PredisTestCase { $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $hashGenerator = $this->getMock('Predis\Cluster\Hash\HashGeneratorInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $hashGenerator = $this->getMockBuilder('Predis\Cluster\Hash\HashGeneratorInterface')->getMock(); $this->assertSame($hashGenerator, $option->filter($options, $hashGenerator)); } @@ -58,10 +58,12 @@ class CRC16Test extends PredisTestCase { $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $hashGenerator = $this->getMock('Predis\Cluster\Hash\HashGeneratorInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $hashGenerator = $this->getMockBuilder('Predis\Cluster\Hash\HashGeneratorInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -73,17 +75,20 @@ class CRC16Test extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\CRC16 expects a valid hash generator */ public function testThrowsExceptionOnInvalidReturnTypeOfHashGeneratorInitializer() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\CRC16 expects a valid hash generator'); + $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $wrongValue = $this->getMock('stdClass'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $wrongValue = $this->getMockBuilder('stdClass')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -100,7 +105,7 @@ class CRC16Test extends PredisTestCase { $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Cluster\Hash\CRC16', $option->filter($options, 'predis')); } @@ -115,21 +120,22 @@ class CRC16Test extends PredisTestCase { $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Cluster\Hash\PhpiredisCRC16', $option->filter($options, 'phpiredis')); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage String value for the crc16 option must be either `predis` or `phpiredis` */ public function testThrowsExceptionOnInvalidShortNameString() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('String value for the crc16 option must be either `predis` or `phpiredis`'); + $option = new CRC16(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, 'unknown'); } diff --git a/tests/Predis/Configuration/Option/ClusterTest.php b/tests/Predis/Configuration/Option/ClusterTest.php index f7ec039e..4359462c 100644 --- a/tests/Predis/Configuration/Option/ClusterTest.php +++ b/tests/Predis/Configuration/Option/ClusterTest.php @@ -25,7 +25,7 @@ class ClusterTest extends PredisTestCase { $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Closure', $initializer = $option->getDefault($options)); $this->assertInstanceOf('Predis\Connection\Cluster\PredisCluster', $initializer($options)); @@ -38,10 +38,12 @@ class ClusterTest extends PredisTestCase { $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -54,17 +56,20 @@ class ClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Cluster expects a valid connection type returned by callable initializer */ public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Cluster expects a valid connection type returned by callable initializer'); + $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -83,7 +88,7 @@ class ClusterTest extends PredisTestCase { $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->never()) ->method('__get') @@ -100,20 +105,20 @@ class ClusterTest extends PredisTestCase { $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->at(0)) ->method('__get') ->with('connections') ->will($this->returnValue( - $this->getMock('Predis\Connection\FactoryInterface') + $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock() )); $options ->expects($this->at(1)) ->method('__get') ->with('crc16') ->will($this->returnValue( - $this->getMock('Predis\Cluster\Hash\HashGeneratorInterface') + $this->getMockBuilder('Predis\Cluster\Hash\HashGeneratorInterface')->getMock() )); $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'redis')); @@ -122,29 +127,31 @@ class ClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage String value for the cluster option must be either `predis` or `redis` */ public function testThrowsExceptionOnInvalidShortNameString() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('String value for the cluster option must be either `predis` or `redis`'); + $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, 'unknown'); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Cluster expects a valid callable */ public function testThrowsExceptionOnInstanceOfClusterInterface() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Cluster expects a valid callable'); + $option = new Cluster(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $option->filter($options, $connection); } diff --git a/tests/Predis/Configuration/Option/CommandsTest.php b/tests/Predis/Configuration/Option/CommandsTest.php index 0683e9b8..17c7f3f0 100644 --- a/tests/Predis/Configuration/Option/CommandsTest.php +++ b/tests/Predis/Configuration/Option/CommandsTest.php @@ -27,7 +27,7 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $commands = $option->getDefault($options); @@ -42,7 +42,7 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->once()) ->method('__isset') @@ -70,7 +70,7 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $input = new RedisFactory(); @@ -87,7 +87,7 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $input = array( 'FOO' => 'Predis\Command\RawCommand', @@ -108,10 +108,12 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -128,14 +130,16 @@ class CommandsTest extends PredisTestCase { $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $dictionary = array( 'FOO' => 'Predis\Command\RawCommand', 'BAR' => 'Predis\Command\RawCommand', ); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -151,16 +155,19 @@ class CommandsTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Commands expects a valid command factory */ public function testThrowsExceptionOnInvalidTypeReturnedByCallable() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Commands expects a valid command factory'); + $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -174,13 +181,14 @@ class CommandsTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Commands expects a valid command factory */ public function testThrowsExceptionOnInvalidValue() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Commands expects a valid command factory'); + $option = new Commands(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, new \stdClass()); } diff --git a/tests/Predis/Configuration/Option/ConnectionsTest.php b/tests/Predis/Configuration/Option/ConnectionsTest.php index 7edc3c3a..2bd09b41 100644 --- a/tests/Predis/Configuration/Option/ConnectionsTest.php +++ b/tests/Predis/Configuration/Option/ConnectionsTest.php @@ -25,7 +25,7 @@ class ConnectionsTest extends PredisTestCase { $option = new Connections(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Connection\Factory', $option->getDefault($options)); } @@ -35,18 +35,20 @@ class ConnectionsTest extends PredisTestCase */ public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings() { - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $class = get_class($this->getMock('Predis\Connection\NodeConnectionInterface')); + $class = get_class($this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock()); $value = array('tcp' => $class, 'redis' => $class); - $default = $this->getMock('Predis\Connection\FactoryInterface'); + $default = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $default ->expects($this->exactly(2)) ->method('define') ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class); - $option = $this->getMock('Predis\Configuration\Option\Connections', array('getDefault')); + $option = $this->getMockBuilder('Predis\Configuration\Option\Connections') + ->setMethods(array('getDefault')) + ->getMock(); $option ->expects($this->once()) ->method('getDefault') @@ -64,9 +66,9 @@ class ConnectionsTest extends PredisTestCase { $parameters = array('database' => 5, 'password' => 'mypassword'); - $default = $this->getMock('Predis\Connection\Factory'); + $default = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->once()) ->method('defined') @@ -89,13 +91,15 @@ class ConnectionsTest extends PredisTestCase */ public function testAcceptsConnectionFactoryInstance() { - $option = $this->getMock('Predis\Configuration\Option\Connections', array('getDefault')); + $option = $this->getMockBuilder('Predis\Configuration\Option\Connections') + ->setMethods(array('getDefault')) + ->getMock(); $option ->expects($this->never()) ->method('getDefault'); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $this->assertSame($factory, $option->filter($options, $factory)); } @@ -107,15 +111,17 @@ class ConnectionsTest extends PredisTestCase { $option = new Connections(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface')) ->will($this->returnValue( - $factory = $this->getMock('Predis\Connection\FactoryInterface') + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock() )); $this->assertSame($factory, $option->filter($options, $callable)); @@ -123,13 +129,14 @@ class ConnectionsTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedException Predis\Configuration\Option\Connections expects a valid command factory */ public function testThrowsExceptionOnInvalidArguments() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Connections expects a valid connection factory'); + $option = new Connections(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, new \stdClass()); } diff --git a/tests/Predis/Configuration/Option/ExceptionsTest.php b/tests/Predis/Configuration/Option/ExceptionsTest.php index 46b044d4..204d96f5 100644 --- a/tests/Predis/Configuration/Option/ExceptionsTest.php +++ b/tests/Predis/Configuration/Option/ExceptionsTest.php @@ -24,7 +24,7 @@ class ExceptionsTest extends PredisTestCase public function testDefaultOptionValue() { $option = new Exceptions(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertTrue($option->getDefault($options)); } @@ -35,7 +35,7 @@ class ExceptionsTest extends PredisTestCase public function testAcceptsDifferentValuesAndFiltersThemAsBooleans() { $option = new Exceptions(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertFalse($option->filter($options, null)); @@ -58,7 +58,7 @@ class ExceptionsTest extends PredisTestCase public function testReturnsFalesOnValuesNotParsableAsBooleans() { $option = new Exceptions(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertFalse($option->filter($options, new \stdClass())); $this->assertFalse($option->filter($options, 'invalid')); diff --git a/tests/Predis/Configuration/Option/PrefixTest.php b/tests/Predis/Configuration/Option/PrefixTest.php index 5d354df2..3b0ff5ba 100644 --- a/tests/Predis/Configuration/Option/PrefixTest.php +++ b/tests/Predis/Configuration/Option/PrefixTest.php @@ -25,7 +25,7 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertNull($option->getDefault($options)); } @@ -37,7 +37,7 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $prefix = $option->filter($options, $value = 'prefix:'); @@ -53,8 +53,8 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $prefix = $option->filter($options, $processor); @@ -68,15 +68,17 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface')) ->will($this->returnValue( - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface') + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock() )); $prefix = $option->filter($options, $callable); @@ -91,9 +93,11 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -114,9 +118,11 @@ class PrefixTest extends PredisTestCase { $option = new Prefix(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $input = $this->getMock('stdClass', array('__toString')); + $input = $this->getMockBuilder('stdClass') + ->setMethods(array('__toString')) + ->getMock(); $input ->expects($this->once()) ->method('__toString') diff --git a/tests/Predis/Configuration/Option/ReplicationTest.php b/tests/Predis/Configuration/Option/ReplicationTest.php index 28e8db8d..08c9be84 100644 --- a/tests/Predis/Configuration/Option/ReplicationTest.php +++ b/tests/Predis/Configuration/Option/ReplicationTest.php @@ -25,7 +25,7 @@ class ReplicationTest extends PredisTestCase { $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Closure', $initializer = $option->getDefault($options)); $this->assertInstanceOf('Predis\Connection\Replication\MasterSlaveReplication', $initializer($options)); @@ -38,9 +38,9 @@ class ReplicationTest extends PredisTestCase { $option = new Replication(); - $connectionFactory = $this->getMock('Predis\Connection\FactoryInterface'); + $connectionFactory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->at(0)) ->method('__get') @@ -69,10 +69,12 @@ class ReplicationTest extends PredisTestCase { $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -85,17 +87,20 @@ class ReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Replication expects a valid connection type returned by callable initializer */ public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Replication expects a valid connection type returned by callable initializer'); + $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -114,7 +119,7 @@ class ReplicationTest extends PredisTestCase { $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'predis')); $this->assertInstanceOf('Predis\Connection\Replication\MasterSlaveReplication', $initializer($parameters = array())); @@ -127,7 +132,7 @@ class ReplicationTest extends PredisTestCase { $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->at(0)) ->method('__get') @@ -138,11 +143,11 @@ class ReplicationTest extends PredisTestCase ->method('__get') ->with('connections') ->will($this->returnValue( - $this->getMock('Predis\Connection\FactoryInterface') + $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock() )); $parameters = array( - $this->getMock('Predis\Connection\NodeConnectionInterface'), + $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(), ); $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'sentinel')); @@ -153,43 +158,46 @@ class ReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage String value for the replication option must be either `predis` or `sentinel` */ public function testThrowsExceptionOnInvalidShortNameString() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('String value for the replication option must be either `predis` or `sentinel`'); + $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, 'unknown'); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Replication expects a valid callable */ public function testThrowsExceptionOnBooleanValue() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Replication expects a valid callable'); + $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, true); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Predis\Configuration\Option\Replication expects a valid callable */ public function testThrowsExceptionOnInstanceOfReplicationInterface() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Predis\Configuration\Option\Replication expects a valid callable'); + $option = new Replication(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connection = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $option->filter($options, $connection); } diff --git a/tests/Predis/Configuration/OptionsTest.php b/tests/Predis/Configuration/OptionsTest.php index e1cdad97..5acd345e 100644 --- a/tests/Predis/Configuration/OptionsTest.php +++ b/tests/Predis/Configuration/OptionsTest.php @@ -39,9 +39,11 @@ class OptionsTest extends PredisTestCase */ public function testConstructorWithArrayArgument() { - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->any()) ->method('__invoke') @@ -51,15 +53,14 @@ class OptionsTest extends PredisTestCase $options = new Options(array( 'exceptions' => false, 'prefix' => 'prefix:', - 'commands' => $this->getMock('Predis\Command\FactoryInterface'), - 'connections' => $this->getMock('Predis\Connection\FactoryInterface'), + 'commands' => $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(), + 'connections' => $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(), 'cluster' => $callable, 'replication' => $callable, 'aggregate' => $callable, )); - $this->assertInternalType('bool', $options->exceptions); - + $this->assertIsBool($options->exceptions); $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $options->prefix); $this->assertInstanceOf('Predis\Command\FactoryInterface', $options->commands); $this->assertInstanceOf('Predis\Connection\FactoryInterface', $options->connections); @@ -157,10 +158,12 @@ class OptionsTest extends PredisTestCase */ public function testLazilyInitializesOptionValueUsingObjectWithInvokeMagicMethod() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); // NOTE: closure values are covered by this test since they define __invoke(). - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -183,7 +186,9 @@ class OptionsTest extends PredisTestCase $custom = new \stdClass(); // NOTE: closure values are covered by this test since they define __invoke(). - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable ->expects($this->once()) ->method('__invoke') @@ -203,7 +208,9 @@ class OptionsTest extends PredisTestCase */ public function testChecksForInvokeMagicMethodDoesNotTriggerAutoloader() { - $trigger = $this->getMock('stdClass', array('autoload')); + $trigger = $this->getMockBuilder('stdClass') + ->setMethods(array('autoload')) + ->getMock(); $trigger ->expects($this->never()) ->method('autoload'); diff --git a/tests/Predis/Connection/Cluster/PredisClusterTest.php b/tests/Predis/Connection/Cluster/PredisClusterTest.php index e003e323..07af8148 100644 --- a/tests/Predis/Connection/Cluster/PredisClusterTest.php +++ b/tests/Predis/Connection/Cluster/PredisClusterTest.php @@ -277,11 +277,12 @@ class PredisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot use 'PING' over clusters of connections. - */ + */ public function testThrowsExceptionOnNonShardableCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Cannot use 'PING' over clusters of connections."); + $ping = $this->getCommandFactory()->createCommand('ping'); $cluster = new PredisCluster(); diff --git a/tests/Predis/Connection/Cluster/RedisClusterTest.php b/tests/Predis/Connection/Cluster/RedisClusterTest.php index 5db584c9..4ac13505 100644 --- a/tests/Predis/Connection/Cluster/RedisClusterTest.php +++ b/tests/Predis/Connection/Cluster/RedisClusterTest.php @@ -26,7 +26,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAcceptsCustomConnectionFactory() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $cluster = new RedisCluster($factory); $this->assertSame($factory, $cluster->getConnectionFactory()); @@ -47,7 +47,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAcceptsCustomClusterStrategy() { - $strategy = $this->getMock('Predis\Cluster\StrategyInterface'); + $strategy = $this->getMockBuilder('Predis\Cluster\StrategyInterface')->getMock(); $cluster = new RedisCluster(new Connection\Factory(), $strategy); @@ -309,7 +309,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383'); $connection4 = $this->getMockConnection('tcp://127.0.0.1:6384'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->at(0)) ->method('create') @@ -328,7 +328,10 @@ class RedisClusterTest extends PredisTestCase ->will($this->returnValue($connection4)); // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster ->expects($this->once()) ->method('getRandomConnection') @@ -629,7 +632,7 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue('value:5001')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -695,7 +698,7 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue('value:1001')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -706,7 +709,10 @@ class RedisClusterTest extends PredisTestCase ->will($this->returnValue($connection4)); // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster ->expects($this->never()) ->method('getRandomConnection'); @@ -724,12 +730,13 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage No connections available in the pool */ public function testThrowsClientExceptionWhenExecutingCommandWithEmptyPool() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No connections available in the pool'); + + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->never()) ->method('create'); @@ -746,7 +753,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAskSlotMapReturnEmptyArrayOnEmptyConnectionsPool() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->never()) ->method('create'); @@ -768,7 +775,8 @@ class RedisClusterTest extends PredisTestCase array(10923, 16383, array('127.0.0.1', 6383), array()), ); - $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); $connection1 + $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); + $connection1 ->expects($this->once()) ->method('executeCommand') ->with($this->isRedisCommand( @@ -798,13 +806,16 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue($slotsmap)); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->never()) ->method('create'); // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster ->expects($this->exactly(3)) ->method('getRandomConnection') @@ -821,11 +832,12 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage Unknown connection error [127.0.0.1:6382] */ public function testAskSlotMapHonorsRetryLimitOnMultipleConnectionFailures() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("Unknown connection error [127.0.0.1:6382]"); + $slotsmap = array( array(0, 5460, array('127.0.0.1', 9381), array()), array(5461, 10922, array('127.0.0.1', 6382), array()), @@ -859,13 +871,16 @@ class RedisClusterTest extends PredisTestCase ->expects($this->never()) ->method('executeCommand'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->never()) ->method('create'); // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster ->expects($this->exactly(2)) ->method('getRandomConnection') @@ -933,7 +948,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory ->expects($this->never()) ->method('create'); @@ -983,7 +998,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1027,7 +1042,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -1069,7 +1084,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1113,7 +1128,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1164,7 +1179,7 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue($response)); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $cluster = new RedisCluster($factory); @@ -1208,7 +1223,7 @@ class RedisClusterTest extends PredisTestCase ->with($cmdGET) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1228,11 +1243,12 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot use 'PING' with redis-cluster. */ public function testThrowsExceptionOnNonSupportedCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Cannot use 'PING' with redis-cluster"); + $ping = $this->getCommandFactory()->createCommand('ping'); $cluster = new RedisCluster(new Connection\Factory()); diff --git a/tests/Predis/Connection/CompositeStreamConnectionTest.php b/tests/Predis/Connection/CompositeStreamConnectionTest.php index 0225e39f..9bbf01b9 100644 --- a/tests/Predis/Connection/CompositeStreamConnectionTest.php +++ b/tests/Predis/Connection/CompositeStreamConnectionTest.php @@ -23,11 +23,12 @@ class CompositeStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index 8d35ed46..b372463f 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -268,7 +268,7 @@ class FactoryTest extends PredisTestCase */ public function testCreateConnectionWithoutInitializationCommands() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('addConnectCommand'); @@ -295,7 +295,7 @@ class FactoryTest extends PredisTestCase 'password' => 'foobar', )); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('getParameters') @@ -309,7 +309,7 @@ class FactoryTest extends PredisTestCase ->method('addConnectCommand') ->with($this->isRedisCommand('SELECT', array(0))); - $factory = new Factory(); + $factory = new Factory(); $reflection = new \ReflectionObject($factory); $prepareConnection = $reflection->getMethod('prepareConnection'); @@ -319,11 +319,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'unknown'. */ public function testCreateUndefinedConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'unknown'"); + $factory = new Factory(); $factory->create(new Parameters(array('scheme' => 'unknown'))); } @@ -357,7 +358,9 @@ class FactoryTest extends PredisTestCase return new $connectionClass($parameters); }; - $initializerMock = $this->getMock('stdClass', array('__invoke')); + $initializerMock = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $initializerMock ->expects($this->exactly(2)) ->method('__invoke') @@ -377,21 +380,23 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException */ public function testDefineConnectionWithInvalidArgument() { + $this->expectException('InvalidArgumentException'); + $factory = new Factory(); $factory->define('foobar', new \stdClass()); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'tcp'. */ public function testUndefineDefinedConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'tcp'"); + $factory = new Factory(); $factory->undefine('tcp'); $factory->create('tcp://127.0.0.1'); @@ -411,11 +416,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'test'. */ public function testDefineAndUndefineConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'test'"); + list(, $connectionClass) = $this->getMockConnectionClass(); $factory = new Factory(); @@ -434,13 +440,15 @@ class FactoryTest extends PredisTestCase { list(, $connectionClass) = $this->getMockConnectionClass(); - $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $cluster ->expects($this->exactly(2)) ->method('add') ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface')); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory') + ->setMethods(array('create')) + ->getMock(); $factory ->expects($this->never()) ->method('create'); @@ -455,13 +463,15 @@ class FactoryTest extends PredisTestCase { list(, $connectionClass) = $this->getMockConnectionClass(); - $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $cluster ->expects($this->exactly(4)) ->method('add') ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface')); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory') + ->setMethods(array('create')) + ->getMock(); $factory ->expects($this->exactly(3)) ->method('create') @@ -477,12 +487,14 @@ class FactoryTest extends PredisTestCase */ public function testAggregateConnectionWithEmptyListOfParameters() { - $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $cluster ->expects($this->never()) ->method('add'); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory') + ->setMethods(array('create')) + ->getMock(); $factory ->expects($this->never()) ->method('create'); @@ -501,7 +513,7 @@ class FactoryTest extends PredisTestCase */ protected function getMockConnectionClass() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); return array($connection, get_class($connection)); } diff --git a/tests/Predis/Connection/ParametersTest.php b/tests/Predis/Connection/ParametersTest.php index bcae2020..29f52848 100644 --- a/tests/Predis/Connection/ParametersTest.php +++ b/tests/Predis/Connection/ParametersTest.php @@ -308,11 +308,12 @@ class ParametersTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid parameters URI: tcp://invalid:uri */ public function testParsingURIThrowOnInvalidURI() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid parameters URI: tcp://invalid:uri"); + Parameters::parse('tcp://invalid:uri'); } diff --git a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php index 0cdbb528..36abb65d 100644 --- a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php @@ -24,11 +24,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'tls'. */ public function testSupportsSchemeTls() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'tls'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'tls')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -36,11 +37,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'rediss'. */ public function testSupportsSchemeRediss() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'rediss'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'rediss')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -48,11 +50,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this @@ -79,11 +82,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group connected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage Cannot resolve the address of 'bogus.tld'. */ public function testThrowsExceptionOnUnresolvableHostname() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("Cannot resolve the address of 'bogus.tld'"); + $connection = $this->createConnectionWithParams(array('host' => 'bogus.tld')); $connection->connect(); } @@ -91,10 +95,11 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $socket = $connection->getResource(); diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php index b94f4ef8..1f65e13a 100644 --- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php @@ -24,11 +24,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage SSL encryption is not supported by this connection backend. */ public function testSupportsSchemeTls() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('SSL encryption is not supported by this connection backend'); + $connection = $this->createConnectionWithParams(array('scheme' => 'tls')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -36,11 +37,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage SSL encryption is not supported by this connection backend. */ public function testSupportsSchemeRediss() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('SSL encryption is not supported by this connection backend'); + $connection = $this->createConnectionWithParams(array('scheme' => 'rediss')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -48,11 +50,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this @@ -81,10 +84,11 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase * @group connected * @group slow * @requires PHP 5.4 - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowsExceptionOnReadWriteTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $connection = $this->createConnectionWithParams(array( 'read_write_timeout' => 0.5, ), true); @@ -97,10 +101,11 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $stream = $connection->getResource(); diff --git a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php index 81634b90..807ce7e9 100644 --- a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php @@ -160,11 +160,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage No available connection for replication */ public function testThrowsExceptionOnEmptyReplication() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No available connection for replication'); + $replication = new MasterSlaveReplication(); $replication->connect(); } @@ -304,11 +305,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorWhenSwitchingToConnectionNotInPool() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found.'); + $replication = new MasterSlaveReplication(); $replication->add($this->getMockConnection('tcp://127.0.0.1:6379?role=master')); @@ -342,11 +344,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorWhenSwitchingToUnknownConnectionByInstance() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found.'); + $replication = new MasterSlaveReplication(); $replication->add($this->getMockConnection('tcp://127.0.0.1:6379?role=master')); @@ -380,11 +383,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorOnSwitchToMasterWithNoMasterDefined() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found.'); + $slave1 = $this->getMockConnection('tcp://127.0.0.1:6380?role=slave'); $replication = new MasterSlaveReplication(); @@ -417,11 +421,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorOnSwitchToRandomSlaveWithNoSlavesDefined() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found.'); + $master = $this->getMockConnection('tcp://127.0.0.1:6379?role=master'); $replication = new MasterSlaveReplication(); @@ -836,11 +841,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Replication\MissingMasterException - * @expectedMessage No master server available for replication */ public function testFailsOnWriteCommandAndNoConnectionSetAsMaster() { + $this->expectException('Predis\Replication\MissingMasterException'); + $this->expectExceptionMessage('No master server available for replication'); + $commands = $this->getCommandFactory(); $cmdSet = $commands->createCommand('set', array('key', 'value')); @@ -904,10 +910,11 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException */ public function testFailsOnUnreachableMaster() { + $this->expectException('Predis\Connection\ConnectionException'); + $commands = $this->getCommandFactory(); $cmdSet = $commands->createCommand('set', array('key', 'value')); @@ -935,11 +942,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The command 'INFO' is not allowed in replication mode. */ public function testThrowsExceptionOnNonSupportedCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The command 'INFO' is not allowed in replication mode."); + $cmd = $this->getCommandFactory()->createCommand('info'); $replication = new MasterSlaveReplication(); @@ -1059,11 +1067,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedMessage Discovery requires a connection factory */ public function testDiscoveryRequiresConnectionFactory() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Discovery requires a connection factory'); + $replication = new MasterSlaveReplication(); $replication->add($this->getMockConnection('tcp://127.0.0.1:6379?role=master')); @@ -1124,7 +1133,7 @@ repl_backlog_histlen:12978 $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory ->expects($this->at(0)) ->method('create') @@ -1222,7 +1231,7 @@ repl_backlog_histlen:12978 $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory ->expects($this->at(0)) ->method('create') @@ -1319,11 +1328,12 @@ repl_backlog_histlen:12978 /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedMessage Automatic discovery requires a connection factory */ public function testAutomaticDiscoveryRequiresConnectionFactory() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Automatic discovery requires a connection factory'); + $master = $this->getMockConnection('tcp://127.0.0.1:6379?role=master'); $replication = new MasterSlaveReplication(); @@ -1345,7 +1355,7 @@ repl_backlog_histlen:12978 $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory ->expects($this->once()) ->method('create') diff --git a/tests/Predis/Connection/Replication/SentinelReplicationTest.php b/tests/Predis/Connection/Replication/SentinelReplicationTest.php index 6ef0afef..899e8856 100644 --- a/tests/Predis/Connection/Replication/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Replication/SentinelReplicationTest.php @@ -24,11 +24,12 @@ class SentinelReplicationTest extends PredisTestCase { /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetSentinelConnectionThrowsExceptionOnEmptySentinelsPool() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $replication = $this->getReplicationConnection('svc', array()); $replication->getSentinelConnection(); } @@ -44,7 +45,13 @@ class SentinelReplicationTest extends PredisTestCase $parameters = $replication->getSentinelConnection()->getParameters()->toArray(); - $this->assertArraySubset(array('database' => null, 'password' => null), $parameters); + $this->assertIsArray($parameters); + + $this->assertArrayHasKey('database', $parameters, 'Missing expected `database` in connection parameters'); + $this->assertNull($parameters['database'], 'Expected `database` connection parameter must be a NULL value'); + + $this->assertArrayHasKey('password', $parameters, 'Missing expected `password` in connection parameters'); + $this->assertNull($parameters['password'], 'Expected `password` connection parameter must be a NULL value'); } /** @@ -205,8 +212,8 @@ class SentinelReplicationTest extends PredisTestCase ->expects($this->exactly(2)) ->method('executeCommand') ->withConsecutive( - $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')), - $this->isRedisCommand('SENTINEL', array('slaves', 'svc')) + array($this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc'))), + array($this->isRedisCommand('SENTINEL', array('slaves', 'svc'))) ) ->will($this->onConsecutiveCalls( // SENTINEL get-master-addr-by-name svc @@ -352,11 +359,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodUpdateSentinelsThrowsExceptionOnNoAvailableSentinel() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $sentinel1 ->expects($this->once()) @@ -382,9 +390,9 @@ class SentinelReplicationTest extends PredisTestCase ->expects($this->exactly(3)) ->method('executeCommand') ->withConsecutive( - $this->isRedisCommand('SENTINEL', array('sentinels', 'svc')), - $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')), - $this->isRedisCommand('SENTINEL', array('slaves', 'svc')) + array($this->isRedisCommand('SENTINEL', array('sentinels', 'svc'))), + array($this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc'))), + array($this->isRedisCommand('SENTINEL', array('slaves', 'svc'))) ) ->will($this->onConsecutiveCalls( // SENTINEL sentinels svc @@ -478,11 +486,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetMasterThrowsExceptionOnNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $sentinel1 ->expects($this->any()) @@ -544,11 +553,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetSlavesThrowsExceptionOnNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $sentinel1 ->expects($this->any()) @@ -567,11 +577,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodConnectThrowsExceptionOnConnectWithEmptySentinelsPool() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $replication = $this->getReplicationConnection('svc', array()); $replication->connect(); } @@ -637,7 +648,7 @@ class SentinelReplicationTest extends PredisTestCase ->expects($this->once()) ->method('connect'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -685,7 +696,7 @@ class SentinelReplicationTest extends PredisTestCase ->expects($this->once()) ->method('connect'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -816,11 +827,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testMethodSwitchToThrowsExceptionOnConnectionNotFound() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found.'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master'); @@ -1014,11 +1026,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\Replication\RoleException - * @expectedExceptionMessage Expected master but got slave [127.0.0.1:6381] */ public function testGetConnectionByCommandThrowsExceptionOnNodeRoleMismatch() { + $this->expectException('Predis\Replication\RoleException'); + $this->expectExceptionMessage('Expected master but got slave [127.0.0.1:6381]'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master'); @@ -1195,7 +1208,7 @@ class SentinelReplicationTest extends PredisTestCase )) ->will($this->returnValue('value')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1260,7 +1273,7 @@ class SentinelReplicationTest extends PredisTestCase )) ->will($this->returnValue(1)); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) ->method('create') @@ -1282,11 +1295,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\Response\ServerException - * @expectedExceptionMessage ERR No such master with that name */ public function testMethodExecuteCommandThrowsExceptionOnUnknownServiceName() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR No such master with that name'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $sentinel1 ->expects($this->any()) @@ -1322,11 +1336,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodExecuteCommandThrowsExceptionOnConnectionFailureAndNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery.'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel'); $sentinel1 ->expects($this->any()) diff --git a/tests/Predis/Connection/StreamConnectionTest.php b/tests/Predis/Connection/StreamConnectionTest.php index 7690be19..753d34b1 100644 --- a/tests/Predis/Connection/StreamConnectionTest.php +++ b/tests/Predis/Connection/StreamConnectionTest.php @@ -23,11 +23,12 @@ class StreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this diff --git a/tests/Predis/Connection/WebdisConnectionTest.php b/tests/Predis/Connection/WebdisConnectionTest.php index 9cdb5a2e..89f0f462 100644 --- a/tests/Predis/Connection/WebdisConnectionTest.php +++ b/tests/Predis/Connection/WebdisConnectionTest.php @@ -45,76 +45,83 @@ class WebdisConnectionTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'tcp'. */ public function testThrowsExceptionOnInvalidScheme() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'tcp'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'tcp')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::writeRequest() is not supported. */ public function testWritingCommandsIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::writeRequest() is not supported"); + $connection = $this->createConnection(); $connection->writeRequest($this->getCommandFactory()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::readResponse() is not supported */ public function testReadingResponsesIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::readResponse() is not supported"); + $connection = $this->createConnection(); $connection->readResponse($this->getCommandFactory()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::read() is not supported. */ public function testReadingFromConnectionIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::read() is not supported"); + $connection = $this->createConnection(); $connection->read(); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported. */ public function testAddingConnectCommandsIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported"); + $connection = $this->createConnection(); $connection->addConnectCommand($this->getCommandFactory()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Command 'SELECT' is not allowed by Webdis. */ public function testRejectCommandSelect() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Command 'SELECT' is not allowed by Webdis"); + $connection = $this->createConnection(); $connection->executeCommand($this->getCommandFactory()->createCommand('select', array(0))); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Command 'AUTH' is not allowed by Webdis. */ public function testRejectCommandAuth() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Command 'AUTH' is not allowed by Webdis"); + $connection = $this->createConnection(); $connection->executeCommand($this->getCommandFactory()->createCommand('auth', array('foobar'))); } @@ -167,10 +174,11 @@ class WebdisConnectionTest extends PredisTestCase * @medium * @group disconnected * @group slow - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowExceptionWhenUnableToConnect() { + $this->expectException('Predis\Connection\ConnectionException'); + $connection = $this->createConnectionWithParams(array('host' => '169.254.10.10')); $connection->executeCommand($this->getCommandFactory()->createCommand('ping')); } diff --git a/tests/Predis/Monitor/ConsumerTest.php b/tests/Predis/Monitor/ConsumerTest.php index 966c8f11..77c60bf0 100644 --- a/tests/Predis/Monitor/ConsumerTest.php +++ b/tests/Predis/Monitor/ConsumerTest.php @@ -22,12 +22,13 @@ class ConsumerTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage 'MONITOR' is not supported by the current command factory. */ public function testMonitorConsumerRequireMonitorCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("'MONITOR' is not supported by the current command factory."); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('supportsCommand') @@ -41,12 +42,13 @@ class ConsumerTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot initialize a monitor consumer over aggregate connections. */ public function testMonitorConsumerDoesNotWorkOnClusters() { - $cluster = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Cannot initialize a monitor consumer over aggregate connections'); + + $cluster = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); $client = new Client($cluster); new MonitorConsumer($client); @@ -58,9 +60,12 @@ class ConsumerTest extends PredisTestCase public function testConstructorStartsConsumer() { $cmdMonitor = $this->getCommandFactory()->createCommand('monitor'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('createCommand', 'executeCommand'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('createCommand', 'executeCommand')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client ->expects($this->once()) ->method('createCommand') @@ -83,9 +88,12 @@ class ConsumerTest extends PredisTestCase */ public function testStoppingConsumerClosesConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client ->expects($this->exactly(2)) ->method('disconnect'); @@ -100,9 +108,12 @@ class ConsumerTest extends PredisTestCase */ public function testGarbageCollectorRunStopsConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client ->expects($this->once()) ->method('disconnect'); @@ -119,7 +130,7 @@ class ConsumerTest extends PredisTestCase { $message = '1323367530.939137 (db 15) "MONITOR"'; - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -144,7 +155,7 @@ class ConsumerTest extends PredisTestCase { $message = '1323367530.939137 [15 127.0.0.1:37265] "MONITOR"'; - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') diff --git a/tests/Predis/Pipeline/AtomicTest.php b/tests/Predis/Pipeline/AtomicTest.php index 7de5fff6..a6a53b97 100644 --- a/tests/Predis/Pipeline/AtomicTest.php +++ b/tests/Predis/Pipeline/AtomicTest.php @@ -28,7 +28,7 @@ class AtomicTest extends PredisTestCase $pong = new Response\Status('PONG'); $queued = new Response\Status('QUEUED'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(2)) ->method('executeCommand') @@ -52,12 +52,13 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The underlying transaction has been aborted by the server. */ public function testThrowsExceptionOnAbortedTransaction() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('The underlying transaction has been aborted by the server'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(2)) ->method('executeCommand') @@ -74,15 +75,16 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testPipelineWithErrorInTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->at(0)) ->method('executeCommand') @@ -107,14 +109,15 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testThrowsServerExceptionOnResponseErrorByDefault() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('readResponse') @@ -137,7 +140,7 @@ class AtomicTest extends PredisTestCase $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(3)) ->method('readResponse') @@ -158,13 +161,13 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The class 'Predis\Pipeline\Atomic' does not support aggregate connections. */ public function testExecutorWithAggregateConnection() { - $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("The class 'Predis\Pipeline\Atomic' does not support aggregate connections"); + $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); $pipeline = new Atomic(new Client($connection)); $pipeline->ping(); diff --git a/tests/Predis/Pipeline/FireAndForgetTest.php b/tests/Predis/Pipeline/FireAndForgetTest.php index 44b68536..7ec7b838 100644 --- a/tests/Predis/Pipeline/FireAndForgetTest.php +++ b/tests/Predis/Pipeline/FireAndForgetTest.php @@ -24,7 +24,7 @@ class FireAndForgetTest extends PredisTestCase */ public function testPipelineWithSingleConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(3)) ->method('writeRequest'); @@ -46,7 +46,8 @@ class FireAndForgetTest extends PredisTestCase */ public function testSwitchesToMasterWithReplicationConnection() { - $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface'); + $connection = $this->getMockBuilder('Predis\Connection\Replication\ReplicationInterface') + ->getMock(); $connection ->expects($this->once()) ->method('switchToMaster'); diff --git a/tests/Predis/Pipeline/PipelineTest.php b/tests/Predis/Pipeline/PipelineTest.php index 7d867ef1..d0aac35d 100644 --- a/tests/Predis/Pipeline/PipelineTest.php +++ b/tests/Predis/Pipeline/PipelineTest.php @@ -37,7 +37,7 @@ class PipelineTest extends PredisTestCase */ public function testCallDoesNotSendCommandsWithoutExecute() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('writeRequest'); @@ -57,7 +57,7 @@ class PipelineTest extends PredisTestCase */ public function testCallReturnsPipelineForFluentInterface() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('writeRequest'); @@ -76,9 +76,9 @@ class PipelineTest extends PredisTestCase */ public function testDoesNotParseComplexResponseObjects() { - $object = $this->getMock('Predis\Response\ResponseInterface'); + $object = $this->getMockBuilder('Predis\Response\ResponseInterface')->getMock(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('readResponse') @@ -93,14 +93,15 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testThrowsServerExceptionOnResponseErrorByDefault() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('readResponse') @@ -119,9 +120,9 @@ class PipelineTest extends PredisTestCase */ public function testReturnsResponseErrorWithClientExceptionsSetToFalse() { - $error = $this->getMock('Predis\Response\ErrorInterface'); + $error = $this->getMockBuilder('Predis\Response\ErrorInterface')->getMock(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(2)) ->method('readResponse') @@ -142,7 +143,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteReturnsPipelineForFluentInterface() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $command = $this->getCommandFactory()->createCommand('echo', array('one')); $pipeline = new Pipeline(new Client($connection)); @@ -155,7 +156,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteCommandDoesNotSendCommandsWithoutExecute() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('writeRequest'); @@ -177,7 +178,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithEmptyBuffer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('writeRequest'); @@ -195,7 +196,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithFilledBuffer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(3)) ->method('writeRequest'); @@ -236,7 +237,7 @@ class PipelineTest extends PredisTestCase */ public function testFlushHandlesPartialBuffers() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(4)) ->method('writeRequest'); @@ -263,7 +264,7 @@ class PipelineTest extends PredisTestCase { $pong = new Response\Status('PONG'); - $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface'); + $connection = $this->getMockBuilder('Predis\Connection\Replication\ReplicationInterface')->getMock(); $connection ->expects($this->once()) ->method('switchToMaster'); @@ -302,10 +303,11 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException */ public function testExecuteDoesNotAcceptNonCallableArgument() { + $this->expectException('InvalidArgumentException'); + $noncallable = new \stdClass(); $pipeline = new Pipeline(new Client()); @@ -314,10 +316,11 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException */ public function testExecuteInsideCallableArgumentThrowsException() { + $this->expectException('Predis\ClientException'); + $pipeline = new Pipeline(new Client()); $pipeline->execute(function ($pipe) { @@ -330,7 +333,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithCallableArgumentRunsPipelineInCallable() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->exactly(4)) ->method('writeRequest'); @@ -356,7 +359,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithCallableArgumentHandlesExceptions() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('writeRequest'); diff --git a/tests/Predis/PredisExceptionTest.php b/tests/Predis/PredisExceptionTest.php index 07b63816..6613c961 100644 --- a/tests/Predis/PredisExceptionTest.php +++ b/tests/Predis/PredisExceptionTest.php @@ -26,7 +26,8 @@ class PredisExceptionTest extends PredisTestCase $message = 'Predis exception message'; $exception = $this->getMockForAbstractClass('Predis\PredisException', array($message)); - $this->setExpectedException('Predis\PredisException', $message); + $this->expectException('Predis\PredisException'); + $this->expectExceptionMessage($message); throw $exception; } diff --git a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php b/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php index c7e692e6..b1f6d207 100644 --- a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php @@ -34,8 +34,8 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testConstructorWithArguments() { - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor($serializer, $reader); @@ -48,7 +48,7 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testCustomRequestSerializer() { - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); $protocol = new CompositeProtocolProcessor(); $protocol->setRequestSerializer($serializer); @@ -61,7 +61,7 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testCustomResponseReader() { - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor(); $protocol->setResponseReader($reader); @@ -76,9 +76,9 @@ class CompositeProtocolProcessorTest extends PredisTestCase { $serialized = "*1\r\n$4\r\nPING\r\n"; - $command = $this->getMock('Predis\Command\CommandInterface'); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); $protocol = new CompositeProtocolProcessor($serializer); @@ -101,8 +101,8 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testConnectionRead() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor(null, $reader); diff --git a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php index b388bd0e..741c17d2 100644 --- a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php @@ -81,11 +81,12 @@ class BulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a bulk response [tcp://127.0.0.1:6379] */ public function testInvalidLengthString() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length for a bulk response [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->never()) @@ -101,11 +102,12 @@ class BulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Value '-5' is not a valid length for a bulk response [tcp://127.0.0.1:6379] */ public function testInvalidLengthInteger() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Value '-5' is not a valid length for a bulk response [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->never()) diff --git a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php index 4e990a82..1f6c9107 100644 --- a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php @@ -25,7 +25,7 @@ class ErrorResponseTest extends PredisTestCase { $message = 'ERR Operation against a key holding the wrong kind of value'; - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); diff --git a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php index 7551dfd3..7e518d74 100644 --- a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php @@ -23,7 +23,7 @@ class IntegerResponseTest extends PredisTestCase */ public function testInteger() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); @@ -44,7 +44,7 @@ class IntegerResponseTest extends PredisTestCase */ public function testNull() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); @@ -59,11 +59,12 @@ class IntegerResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid numeric response [tcp://127.0.0.1:6379] */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid numeric response [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->never()) diff --git a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php index 2d2e3126..3d616929 100644 --- a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php @@ -23,7 +23,7 @@ class MultiBulkResponseTest extends PredisTestCase */ public function testMultiBulk() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->once()) ->method('getProtocol') @@ -55,7 +55,7 @@ class MultiBulkResponseTest extends PredisTestCase */ public function testNull() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); @@ -70,11 +70,12 @@ class MultiBulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length of a multi-bulk response [tcp://127.0.0.1:6379] */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length of a multi-bulk response [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->never()) diff --git a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php index 45583970..857bb5fc 100644 --- a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php @@ -23,7 +23,7 @@ class StatusResponseTest extends PredisTestCase */ public function testOk() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); @@ -43,7 +43,7 @@ class StatusResponseTest extends PredisTestCase */ public function testQueued() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); @@ -63,7 +63,7 @@ class StatusResponseTest extends PredisTestCase */ public function testPlainString() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface'); $connection ->expects($this->never()) ->method('readLine'); diff --git a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php index 184f5270..ee6c0e9f 100644 --- a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php @@ -23,7 +23,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase */ public function testOk() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection ->expects($this->never()) ->method('readLine'); @@ -38,11 +38,12 @@ class StreamableMultiBulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a multi-bulk response [tcp://127.0.0.1:6379] */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length for a multi-bulk response [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->never()) diff --git a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php index 2e03a231..ab9ce292 100644 --- a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php @@ -26,7 +26,7 @@ class ProtocolProcessorTest extends PredisTestCase $serialized = "*1\r\n$4\r\nPING\r\n"; $protocol = new ProtocolProcessor(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->once()) ->method('getId') @@ -100,11 +100,12 @@ class ProtocolProcessorTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unknown response prefix: '!' [tcp://127.0.0.1:6379] */ public function testUnknownResponsePrefix() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Unknown response prefix: '!' [tcp://127.0.0.1:6379]"); + $protocol = new ProtocolProcessor(); $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); diff --git a/tests/Predis/Protocol/Text/RequestSerializerTest.php b/tests/Predis/Protocol/Text/RequestSerializerTest.php index fe945674..fec2ca5c 100644 --- a/tests/Predis/Protocol/Text/RequestSerializerTest.php +++ b/tests/Predis/Protocol/Text/RequestSerializerTest.php @@ -25,7 +25,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->once()) ->method('getId') @@ -47,7 +47,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->once()) ->method('getId') @@ -69,7 +69,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->once()) ->method('getId') diff --git a/tests/Predis/Protocol/Text/ResponseReaderTest.php b/tests/Predis/Protocol/Text/ResponseReaderTest.php index 594cbaab..ee021f52 100644 --- a/tests/Predis/Protocol/Text/ResponseReaderTest.php +++ b/tests/Predis/Protocol/Text/ResponseReaderTest.php @@ -39,7 +39,7 @@ class ResponseReaderTest extends PredisTestCase */ public function testReplaceHandler() { - $handler = $this->getMock('Predis\Protocol\Text\Handler\ResponseHandlerInterface'); + $handler = $this->getMockBuilder('Predis\Protocol\Text\Handler\ResponseHandlerInterface')->getMock(); $reader = new ResponseReader(); $reader->setHandler('+', $handler); @@ -85,11 +85,12 @@ class ResponseReaderTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unexpected empty reponse header [tcp://127.0.0.1:6379] */ public function testEmptyResponseHeader() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage('Unexpected empty reponse header [tcp://127.0.0.1:6379]'); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->once()) @@ -99,13 +100,15 @@ class ResponseReaderTest extends PredisTestCase $reader = new ResponseReader(); $reader->read($connection); } + /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unknown response prefix: '!' [tcp://127.0.0.1:6379] */ public function testUnknownResponsePrefix() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Unknown response prefix: '!' [tcp://127.0.0.1:6379]"); + $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection ->expects($this->once()) diff --git a/tests/Predis/PubSub/ConsumerTest.php b/tests/Predis/PubSub/ConsumerTest.php index 44447271..c69a7a15 100644 --- a/tests/Predis/PubSub/ConsumerTest.php +++ b/tests/Predis/PubSub/ConsumerTest.php @@ -22,12 +22,13 @@ class ConsumerTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage PUB/SUB commands are not supported by the current command factory. */ public function testPubSubConsumerRequirePubSubRelatedCommand() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('PUB/SUB commands are not supported by the current command factory.'); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->any()) ->method('supportsCommands') @@ -40,12 +41,13 @@ class ConsumerTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot initialize a PUB/SUB consumer over aggregate connections. */ public function testPubSubConsumerDoesNotWorkOnClusters() { - $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Cannot initialize a PUB/SUB consumer over aggregate connections'); + + $cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $client = new Client($cluster); new PubSubConsumer($client); @@ -56,10 +58,15 @@ class ConsumerTest extends PredisTestCase */ public function testConstructorWithoutSubscriptionsDoesNotStartConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('executeCommand'), array($connection)); - $client->expects($this->never())->method('executeCommand'); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('executeCommand')) + ->setConstructorArgs(array($connection)) + ->getMock(); + + $client->expects($this->never()) + ->method('executeCommand'); new PubSubConsumer($client); } @@ -71,10 +78,13 @@ class ConsumerTest extends PredisTestCase { $commands = $this->getCommandFactory(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(2))->method('writeRequest'); - $client = $this->getMock('Predis\Client', array('createCommand', 'writeRequest'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('createCommand', 'writeRequest')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client ->expects($this->exactly(2)) ->method('createCommand') @@ -93,9 +103,12 @@ class ConsumerTest extends PredisTestCase */ public function testStoppingConsumerWithTrueClosesConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client ->expects($this->once()) ->method('disconnect'); @@ -116,9 +129,12 @@ class ConsumerTest extends PredisTestCase $classUnsubscribe = $commands->getCommandClass('unsubscribe'); $classPunsubscribe = $commands->getCommandClass('punsubscribe'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*'); $pubsub = new PubSubConsumer($client, $options); @@ -139,8 +155,11 @@ class ConsumerTest extends PredisTestCase */ public function testIsNotValidWhenNotSubscribed() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $pubsub = new PubSubConsumer($client); @@ -155,7 +174,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pong', ''); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -176,7 +195,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pong', 'foobar'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -197,7 +216,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('message', 'channel:foo', 'message from channel'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -219,7 +238,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pmessage', 'channel:*', 'channel:foo', 'message from channel'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -242,7 +261,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('subscribe', 'channel:foo', 1); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -264,7 +283,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('unsubscribe', 'channel:foo', 1); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -286,7 +305,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('unsubscribe', 'channel:foo', 0); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->once()) ->method('read') @@ -310,7 +329,7 @@ class ConsumerTest extends PredisTestCase */ public function testGetUnderlyingClientInstance() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $pubsub = new PubSubConsumer($client); diff --git a/tests/Predis/PubSub/DispatcherLoopTest.php b/tests/Predis/PubSub/DispatcherLoopTest.php index c4db7212..c5560c54 100644 --- a/tests/Predis/PubSub/DispatcherLoopTest.php +++ b/tests/Predis/PubSub/DispatcherLoopTest.php @@ -46,7 +46,9 @@ class DispatcherLoopTest extends PredisTestCase $pubsub = new Consumer($consumer); $dispatcher = new DispatcherLoop($pubsub); - $function01 = $this->getMock('stdClass', array('__invoke')); + $function01 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function01 ->expects($this->exactly(2)) ->method('__invoke') @@ -60,13 +62,17 @@ class DispatcherLoopTest extends PredisTestCase } })); - $function02 = $this->getMock('stdClass', array('__invoke')); + $function02 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function02 ->expects($this->once()) ->method('__invoke') ->with('02:argument'); - $function03 = $this->getMock('stdClass', array('__invoke')); + $function03 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function03 ->expects($this->never()) ->method('__invoke'); @@ -109,7 +115,9 @@ class DispatcherLoopTest extends PredisTestCase $pubsub = new Consumer($consumer); $dispatcher = new DispatcherLoop($pubsub); - $callback = $this->getMock('stdClass', array('__invoke')); + $callback = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callback ->expects($this->exactly(1)) ->method('__invoke') diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index bde9f17b..892c1d65 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/tests/Predis/Replication/ReplicationStrategyTest.php @@ -194,11 +194,12 @@ class ReplicationStrategyTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The command 'INFO' is not allowed in replication mode. */ public function testUsingDisallowedCommandThrowsException() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The command 'INFO' is not allowed in replication mode"); + $commands = $this->getCommandFactory(); $strategy = new ReplicationStrategy(); @@ -213,7 +214,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->any()) ->method('getId') @@ -229,7 +230,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->any()) ->method('getId') @@ -246,7 +247,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command ->expects($this->any()) ->method('getId') @@ -309,7 +310,9 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript')) + ->getMock(); $command ->expects($this->any()) ->method('getScript') @@ -333,7 +336,9 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript')) + ->getMock(array('getScript')); $command ->expects($this->any()) ->method('getScript') diff --git a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php index 2e5b6670..dca06bc7 100644 --- a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php +++ b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php @@ -23,12 +23,13 @@ class MultiBulkTupleTest extends PredisTestCase { /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Cannot initialize a tuple iterator using an already initiated iterator. */ public function testInitiatedMultiBulkIteratorsAreNotValid() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Cannot initialize a tuple iterator using an already initiated iterator'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $iterator = new MultiBulk($connection, 2); $iterator->next(); @@ -38,12 +39,13 @@ class MultiBulkTupleTest extends PredisTestCase /** * @group disconnected - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Invalid response size for a tuple iterator. */ public function testMultiBulkWithOddSizesAreInvalid() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('UnexpectedValueException'); + $this->expectExceptionMessage('Invalid response size for a tuple iterator'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $iterator = new MultiBulk($connection, 3); diff --git a/tests/Predis/Response/ServerExceptionTest.php b/tests/Predis/Response/ServerExceptionTest.php index b74e66bf..9aa7acd3 100644 --- a/tests/Predis/Response/ServerExceptionTest.php +++ b/tests/Predis/Response/ServerExceptionTest.php @@ -25,7 +25,8 @@ class ServerExceptionTest extends PredisTestCase */ public function testExceptionMessage() { - $this->setExpectedException('Predis\Response\ServerException', self::ERR_WRONG_KEY_TYPE); + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage(self::ERR_WRONG_KEY_TYPE); throw new ServerException(self::ERR_WRONG_KEY_TYPE); } diff --git a/tests/Predis/Transaction/MultiExecTest.php b/tests/Predis/Transaction/MultiExecTest.php index b08a5e39..ab91a1d6 100644 --- a/tests/Predis/Transaction/MultiExecTest.php +++ b/tests/Predis/Transaction/MultiExecTest.php @@ -23,19 +23,20 @@ class MultiExecTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage MULTI, EXEC and DISCARD are not supported by the current command factory. */ public function testThrowsExceptionOnUnsupportedMultiExecInCommandFactory() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('MULTI, EXEC and DISCARD are not supported by the current command factory.'); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('supportsCommands') ->with(array('MULTI', 'EXEC', 'DISCARD')) ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('commands' => $commands)); new MultiExec($client); @@ -43,12 +44,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage WATCH is not supported by the current command factory. */ public function testThrowsExceptionOnUnsupportedWatchInCommandFactory() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('WATCH is not supported by the current command factory.'); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('supportsCommands') @@ -60,7 +62,7 @@ class MultiExecTest extends PredisTestCase ->with('WATCH') ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('commands' => $commands)); $tx = new MultiExec($client, array('options' => 'cas')); @@ -69,12 +71,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage UNWATCH is not supported by the current command factory. */ public function testThrowsExceptionOnUnsupportedUnwatchInCommandFactory() { - $commands = $this->getMock('Predis\Command\FactoryInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('UNWATCH is not supported by the current command factory.'); + + $commands = $this->getMockBuilder('Predis\Command\FactoryInterface')->getMock(); $commands ->expects($this->once()) ->method('supportsCommands') @@ -86,7 +89,7 @@ class MultiExecTest extends PredisTestCase ->with('UNWATCH') ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('commands' => $commands)); $tx = new MultiExec($client, array('options' => 'cas')); @@ -174,11 +177,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Cannot invoke "execute" or "exec" inside an active transaction context. */ public function testThrowsExceptionOnExecInsideTransactionBlock() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Cannot invoke "execute" or "exec" inside an active transaction context'); + $commands = array(); $callback = $this->getExecuteCallback(null, $commands); @@ -252,10 +256,11 @@ class MultiExecTest extends PredisTestCase } /** * @group disconnected - * @expectedException \Predis\ClientException */ public function testThrowsExceptionOnWatchInsideMulti() { + $this->expectException('Predis\ClientException'); + $callback = $this->getExecuteCallback(); $tx = $this->getMockedTransaction($callback); @@ -402,11 +407,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Automatic retries are supported only when a callable block is provided. */ public function testThrowsExceptionOnAutomaticRetriesWithFluentInterface() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Automatic retries are supported only when a callable block is provided'); + + $options = array('retry' => 1); $callback = $this->getExecuteCallback(); @@ -424,7 +431,9 @@ class MultiExecTest extends PredisTestCase $expected = array('bar'); $options = array('watch' => array('foo', 'bar'), 'retry' => ($attempts = 2) + 1); - $sentinel = $this->getMock('stdClass', array('signal')); + $sentinel = $this->getMockBuilder('stdClass') + ->setMethods(array('signal')) + ->getMock(); $sentinel->expects($this->exactly($attempts))->method('signal'); $callback = $this->getExecuteCallback($expected, $txCommands, $casCommands); @@ -449,10 +458,11 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Transaction\AbortedMultiExecException */ public function testThrowsExceptionOnServerSideTransactionAbort() { + $this->expectException('Predis\Transaction\AbortedMultiExecException'); + $callback = $this->getExecuteCallback(); $tx = $this->getMockedTransaction($callback); @@ -485,7 +495,8 @@ class MultiExecTest extends PredisTestCase // NOOP } - $this->assertNull($responses, $expected); + $this->assertNull($responses); + $this->assertIsArray($expected); $this->assertSame(array('MULTI', 'SET', 'GET', 'DISCARD'), self::commandsToIDs($commands)); } @@ -595,11 +606,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR simulated error */ public function testExceptionsOptionTakesPrecedenceOverClientOptionsWhenTrue() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR simulated error'); + $expected = array('before', new Response\Error('ERR simulated error'), 'after'); $connection = $this->getMockedConnection(function (CommandInterface $command) use ($expected) { @@ -623,11 +635,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR simulated failure on EXEC */ public function testExceptionsOptionDoesNotAffectTransactionControlCommands() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR simulated failure on EXEC'); + $connection = $this->getMockedConnection(function (CommandInterface $command) { switch ($command->getId()) { case 'MULTI': @@ -777,7 +790,7 @@ class MultiExecTest extends PredisTestCase $tx->mget('foo', 'foobar'); }); - $this->assertInternalType('array', $responses); + $this->assertIsArray($responses); $this->assertSame(array(array('bar', null)), $responses); $hijack = true; @@ -800,7 +813,7 @@ class MultiExecTest extends PredisTestCase $tx->mget('foo', 'foobar'); }); - $this->assertInternalType('array', $responses); + $this->assertIsArray($responses); $this->assertSame(array(array('hijacked!', null)), $responses); } @@ -818,7 +831,7 @@ class MultiExecTest extends PredisTestCase */ protected function getMockedConnection($executeCallback) { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection ->expects($this->any()) ->method('executeCommand')