diff --git a/.travis.yml b/.travis.yml index 96ba9fc..3fbff2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,10 @@ php: - 7.0 - 7.1 - 7.2 + - nightly +allow_failures: + - php: nightly + install: - yes '' | pecl install -f redis diff --git a/tests/CredisClusterTest.php b/tests/CredisClusterTest.php index c72d629..311ce5f 100644 --- a/tests/CredisClusterTest.php +++ b/tests/CredisClusterTest.php @@ -64,7 +64,7 @@ public function testAlias() $this->assertEquals($config['port'],$this->cluster->client($offset)->getPort()); } $alias = "non-existent-alias"; - $this->expectException('CredisException',"Client $alias does not exist."); + $this->setExpectedExceptionShim('CredisException',"Client $alias does not exist."); $this->cluster->client($alias); } public function testMasterSlave() @@ -92,7 +92,7 @@ public function testMasterSlave() $this->waitForSlaveReplication(); $this->assertEquals('value',$this->cluster->client('slave')->get('key')); $this->assertEquals('value',$this->cluster->get('key')); - $this->expectException('CredisException'); + $this->setExpectedExceptionShim('CredisException'); $this->assertFalse($this->cluster->client('slave')->set('key2','value')); } public function testMasterWithoutSlavesAndWriteOnlyFlag() @@ -185,7 +185,7 @@ public function testCredisClientInstancesInConstructor() $this->cluster = new Credis_Cluster(array($two,$three,$four),2,$this->useStandalone); $this->assertTrue($this->cluster->set('key','value')); $this->assertEquals('value',$this->cluster->get('key')); - $this->expectException('CredisException','Server should either be an array or an instance of Credis_Client'); + $this->setExpectedExceptionShim('CredisException','Server should either be an array or an instance of Credis_Client'); new Credis_Cluster(array(new stdClass()),2,$this->useStandalone); } public function testSetMasterClient() diff --git a/tests/CredisSentinelTest.php b/tests/CredisSentinelTest.php index 12e9d14..01d1497 100644 --- a/tests/CredisSentinelTest.php +++ b/tests/CredisSentinelTest.php @@ -42,7 +42,7 @@ public function testMasterClient() $master = $this->sentinel->getMasterClient($this->sentinelConfig->clustername); $this->assertInstanceOf('Credis_Client',$master); $this->assertEquals($this->redisConfig[0]['port'],$master->getPort()); - $this->expectException('CredisException','Master not found'); + $this->setExpectedExceptionShim('CredisException','Master not found'); $this->sentinel->getMasterClient('non-existing-cluster'); } public function testMasters() @@ -73,7 +73,7 @@ public function testMaster() $this->assertEquals($this->sentinelConfig->clustername,$master[1]); $this->assertEquals($this->redisConfig[0]['port'],$master[5]); - $this->expectException('CredisException','No such master with that name'); + $this->setExpectedExceptionShim('CredisException','No such master with that name'); $this->sentinel->master('non-existing-cluster'); } public function testSlaveClient() @@ -84,7 +84,7 @@ public function testSlaveClient() foreach($slaves as $slave){ $this->assertInstanceOf('Credis_Client',$slave); } - $this->expectException('CredisException','No such master with that name'); + $this->setExpectedExceptionShim('CredisException','No such master with that name'); $this->sentinel->getSlaveClients('non-existing-cluster'); } public function testSlaves() @@ -100,12 +100,12 @@ public function testSlaves() $this->assertInternalType('array',$slaves); $this->assertCount(0,$slaves); - $this->expectException('CredisException','No such master with that name'); + $this->setExpectedExceptionShim('CredisException','No such master with that name'); $this->sentinel->slaves('non-existing-cluster'); } public function testNonExistingClusterNameWhenCreatingSlaves() { - $this->expectException('CredisException','No such master with that name'); + $this->setExpectedExceptionShim('CredisException','No such master with that name'); $this->sentinel->createSlaveClients('non-existing-cluster'); } public function testCreateCluster() @@ -116,7 +116,7 @@ public function testCreateCluster() $cluster = $this->sentinel->createCluster($this->sentinelConfig->clustername,0,1,false); $this->assertInstanceOf('Credis_Cluster',$cluster); $this->assertCount(2,$cluster->clients()); - $this->expectException('CredisException','The master is down'); + $this->setExpectedExceptionShim('CredisException','The master is down'); $this->sentinel->createCluster($this->sentinelConfig->downclustername); } public function testGetCluster() @@ -155,7 +155,7 @@ public function testGetHostAndPort() $host = 'localhost'; $port = '123456'; - $client = $this->createMock('\Credis_Client'); + $client = $this->createMockShim('\Credis_Client'); $sentinel = new Credis_Sentinel($client); $client->expects($this->once())->method('getHost')->willReturn($host); @@ -166,7 +166,7 @@ public function testGetHostAndPort() } public function testNonExistingMethod() { - $this->expectException('CredisException','Unknown sentinel subcommand \'bla\''); + $this->setExpectedExceptionShim('CredisException','Unknown sentinel subcommand \'bla\''); $this->sentinel->bla(); } } diff --git a/tests/CredisStandaloneClusterTest.php b/tests/CredisStandaloneClusterTest.php index 886cc35..4f42b75 100644 --- a/tests/CredisStandaloneClusterTest.php +++ b/tests/CredisStandaloneClusterTest.php @@ -24,7 +24,7 @@ public function testMasterSlave() $this->waitForSlaveReplication(); $this->assertEquals('value',$this->cluster->client('slave')->get('key')); $this->assertEquals('value',$this->cluster->get('key')); - $this->expectException('CredisException','READONLY You can\'t write against a read only slave.'); + $this->setExpectedExceptionShim('CredisException','READONLY You can\'t write against a read only slave.'); $this->cluster->client('slave')->set('key2','value'); } } diff --git a/tests/CredisStandaloneTest.php b/tests/CredisStandaloneTest.php index ac60ebf..f47514d 100644 --- a/tests/CredisStandaloneTest.php +++ b/tests/CredisStandaloneTest.php @@ -38,7 +38,7 @@ public function testStandAloneArgumentsExtra() public function testStandAloneMultiPipelineThrowsException() { - $this->expectException('CredisException','A pipeline is already in use and only one pipeline is supported.'); + $this->setExpectedExceptionShim('CredisException','A pipeline is already in use and only one pipeline is supported.'); $this->credis->pipeline()->pipeline(); } } diff --git a/tests/CredisTest.php b/tests/CredisTest.php index 729f54e..d6fac5e 100644 --- a/tests/CredisTest.php +++ b/tests/CredisTest.php @@ -622,7 +622,7 @@ public function testGettersAndSetters() $this->credis->forceStandalone(); } $this->credis->setMaxConnectRetries(1); - $this->expectException('CredisException','Connection to Redis localhost:12345 failed after 2 failures.'); + $this->setExpectedExceptionShim('CredisException','Connection to Redis localhost:12345 failed after 2 failures.'); $this->credis->connect(); } @@ -664,7 +664,7 @@ public function testConnectionStringsSocket() public function testInvalidTcpConnectionstring() { $this->credis->close(); - $this->expectException('CredisException','Invalid host format; expected tcp://host[:port][/persistence_identifier]'); + $this->setExpectedExceptionShim('CredisException','Invalid host format; expected tcp://host[:port][/persistence_identifier]'); $this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':abc'); if ($this->useStandalone) { $this->credis->forceStandalone(); @@ -674,7 +674,7 @@ public function testInvalidTcpConnectionstring() public function testInvalidUnixSocketConnectionstring() { $this->credis->close(); - $this->expectException('CredisException','Invalid unix socket format; expected unix:///path/to/redis.sock'); + $this->setExpectedExceptionShim('CredisException','Invalid unix socket format; expected unix:///path/to/redis.sock'); $this->credis = new Credis_Client('unix://path/to/redis.sock'); if ($this->useStandalone) { $this->credis->forceStandalone(); @@ -685,7 +685,7 @@ public function testForceStandAloneAfterEstablishedConnection() { $this->credis->connect(); if ( ! $this->useStandalone) { - $this->expectException('CredisException','Cannot force Credis_Client to use standalone PHP driver after a connection has already been established.'); + $this->setExpectedExceptionShim('CredisException','Cannot force Credis_Client to use standalone PHP driver after a connection has already been established.'); } $this->credis->forceStandalone(); $this->assertTrue(true); diff --git a/tests/CredisTestCommon.php b/tests/CredisTestCommon.php index b50e11a..7e72eab 100644 --- a/tests/CredisTestCommon.php +++ b/tests/CredisTestCommon.php @@ -150,23 +150,29 @@ public static function tearDownAfterClass() @copy('redis-sentinel.conf.bak','redis-sentinel.conf'); } } - + + + // /** + * php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue + * This is due to the defined return type + * * Polyfill for older PHPUnit */ - public function createMock($class) + protected function createMockShim($originalClassName) { if (method_exists($this, 'getMock')) { - return $this->getMock($class); + return $this->getMock($originalClassName); } else { - return parent::createMock($class); + return parent::createMock($originalClassName); } } - + /** - * Polyfill for older PHPUnit + * php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue + * This is due to the defined return type */ - public function expectException($class, $message = NULL, $code = NULL) + public function setExpectedExceptionShim($class, $message = NULL, $code = NULL) { if (method_exists($this, 'setExpectedException')) { $this->setExpectedException($class, $message, $code);