From 7ca728b29c9cbf70dbcbba592c240170575b118e Mon Sep 17 00:00:00 2001 From: Xon Date: Sat, 10 Mar 2018 23:36:27 +0800 Subject: [PATCH 1/7] Start testing on php 7.3 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 96ba9fc..8c59f13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 install: - yes '' | pecl install -f redis From 2c180b5f6926977ce0122f3b20ed45b5e60e6cc7 Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:07:33 +0800 Subject: [PATCH 2/7] Unit Tests - php 7.2 compat fix --- tests/CredisClusterTest.php | 6 +++--- tests/CredisSentinelTest.php | 14 +++++++------- tests/CredisStandaloneClusterTest.php | 2 +- tests/CredisStandaloneTest.php | 2 +- tests/CredisTest.php | 8 ++++---- tests/CredisTestCommon.php | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) 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..63e43f7 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() @@ -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..ab1f31b 100644 --- a/tests/CredisTestCommon.php +++ b/tests/CredisTestCommon.php @@ -150,7 +150,7 @@ public static function tearDownAfterClass() @copy('redis-sentinel.conf.bak','redis-sentinel.conf'); } } - + /** * Polyfill for older PHPUnit */ @@ -162,11 +162,11 @@ public function createMock($class) return parent::createMock($class); } } - + /** - * Polyfill for older PHPUnit + * php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue */ - 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); From 3b5156c94d06ac6bff02ed94e9df6ad5f9c87cb6 Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:13:15 +0800 Subject: [PATCH 3/7] Fix php 7.2: Declaration of CredisTestCommon::createMock($class) must be compatible with PHPUnit\Framework\TestCase::createMock($originalClassName) --- tests/CredisTestCommon.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CredisTestCommon.php b/tests/CredisTestCommon.php index ab1f31b..1881790 100644 --- a/tests/CredisTestCommon.php +++ b/tests/CredisTestCommon.php @@ -154,12 +154,12 @@ public static function tearDownAfterClass() /** * Polyfill for older PHPUnit */ - public function createMock($class) + public function createMock($originalClassName) { if (method_exists($this, 'getMock')) { - return $this->getMock($class); + return $this->getMock($originalClassName); } else { - return parent::createMock($class); + return parent::createMock($originalClassName); } } From 5831165afe2d1db92047575c06108f9c5d91aaae Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:19:39 +0800 Subject: [PATCH 4/7] Fix php 7.2: Declaration of CredisTestCommon::createMock($class) must be compatible with PHPUnit\Framework\TestCase::createMock($originalClassName) take #2 --- tests/CredisTestCommon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CredisTestCommon.php b/tests/CredisTestCommon.php index 1881790..65ed64d 100644 --- a/tests/CredisTestCommon.php +++ b/tests/CredisTestCommon.php @@ -154,7 +154,7 @@ public static function tearDownAfterClass() /** * Polyfill for older PHPUnit */ - public function createMock($originalClassName) + protected function createMock($originalClassName) { if (method_exists($this, 'getMock')) { return $this->getMock($originalClassName); From e22b89cc9f0dbbd2ae912cc247710ce6829c0cd9 Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:20:25 +0800 Subject: [PATCH 5/7] Revert "Start testing on php 7.3" This reverts commit 7ca728b29c9cbf70dbcbba592c240170575b118e. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c59f13..96ba9fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ php: - 7.0 - 7.1 - 7.2 - - 7.3 install: - yes '' | pecl install -f redis From d78e4dae30598c48f6ed6912b925fe30db448aaa Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:27:01 +0800 Subject: [PATCH 6/7] Instead of php 7.3, test against nightly --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) 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 From f3f0bec7337ed806a34b12ee8e79dc86f8cbadba Mon Sep 17 00:00:00 2001 From: Xon Date: Sun, 11 Mar 2018 00:31:11 +0800 Subject: [PATCH 7/7] Shim createMock for php7.2 compatibility --- tests/CredisSentinelTest.php | 2 +- tests/CredisTestCommon.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/CredisSentinelTest.php b/tests/CredisSentinelTest.php index 63e43f7..01d1497 100644 --- a/tests/CredisSentinelTest.php +++ b/tests/CredisSentinelTest.php @@ -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); diff --git a/tests/CredisTestCommon.php b/tests/CredisTestCommon.php index 65ed64d..7e72eab 100644 --- a/tests/CredisTestCommon.php +++ b/tests/CredisTestCommon.php @@ -151,10 +151,15 @@ public static function tearDownAfterClass() } } + + // /** + * 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 */ - protected function createMock($originalClassName) + protected function createMockShim($originalClassName) { if (method_exists($this, 'getMock')) { return $this->getMock($originalClassName); @@ -165,6 +170,7 @@ protected function createMock($originalClassName) /** * 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 setExpectedExceptionShim($class, $message = NULL, $code = NULL) {