Skip to content

Commit 6477dac

Browse files
Merge pull request #99 from Xon/patch-1
Unit Test updates (php7.2 fixes & enable for php 7.3 when it comes out)
2 parents f5aa18c + f3f0bec commit 6477dac

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ php:
66
- 7.0
77
- 7.1
88
- 7.2
9+
- nightly
10+
allow_failures:
11+
- php: nightly
12+
913

1014
install:
1115
- yes '' | pecl install -f redis

tests/CredisClusterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testAlias()
6464
$this->assertEquals($config['port'],$this->cluster->client($offset)->getPort());
6565
}
6666
$alias = "non-existent-alias";
67-
$this->expectException('CredisException',"Client $alias does not exist.");
67+
$this->setExpectedExceptionShim('CredisException',"Client $alias does not exist.");
6868
$this->cluster->client($alias);
6969
}
7070
public function testMasterSlave()
@@ -92,7 +92,7 @@ public function testMasterSlave()
9292
$this->waitForSlaveReplication();
9393
$this->assertEquals('value',$this->cluster->client('slave')->get('key'));
9494
$this->assertEquals('value',$this->cluster->get('key'));
95-
$this->expectException('CredisException');
95+
$this->setExpectedExceptionShim('CredisException');
9696
$this->assertFalse($this->cluster->client('slave')->set('key2','value'));
9797
}
9898
public function testMasterWithoutSlavesAndWriteOnlyFlag()
@@ -185,7 +185,7 @@ public function testCredisClientInstancesInConstructor()
185185
$this->cluster = new Credis_Cluster(array($two,$three,$four),2,$this->useStandalone);
186186
$this->assertTrue($this->cluster->set('key','value'));
187187
$this->assertEquals('value',$this->cluster->get('key'));
188-
$this->expectException('CredisException','Server should either be an array or an instance of Credis_Client');
188+
$this->setExpectedExceptionShim('CredisException','Server should either be an array or an instance of Credis_Client');
189189
new Credis_Cluster(array(new stdClass()),2,$this->useStandalone);
190190
}
191191
public function testSetMasterClient()

tests/CredisSentinelTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testMasterClient()
4242
$master = $this->sentinel->getMasterClient($this->sentinelConfig->clustername);
4343
$this->assertInstanceOf('Credis_Client',$master);
4444
$this->assertEquals($this->redisConfig[0]['port'],$master->getPort());
45-
$this->expectException('CredisException','Master not found');
45+
$this->setExpectedExceptionShim('CredisException','Master not found');
4646
$this->sentinel->getMasterClient('non-existing-cluster');
4747
}
4848
public function testMasters()
@@ -73,7 +73,7 @@ public function testMaster()
7373
$this->assertEquals($this->sentinelConfig->clustername,$master[1]);
7474
$this->assertEquals($this->redisConfig[0]['port'],$master[5]);
7575

76-
$this->expectException('CredisException','No such master with that name');
76+
$this->setExpectedExceptionShim('CredisException','No such master with that name');
7777
$this->sentinel->master('non-existing-cluster');
7878
}
7979
public function testSlaveClient()
@@ -84,7 +84,7 @@ public function testSlaveClient()
8484
foreach($slaves as $slave){
8585
$this->assertInstanceOf('Credis_Client',$slave);
8686
}
87-
$this->expectException('CredisException','No such master with that name');
87+
$this->setExpectedExceptionShim('CredisException','No such master with that name');
8888
$this->sentinel->getSlaveClients('non-existing-cluster');
8989
}
9090
public function testSlaves()
@@ -100,12 +100,12 @@ public function testSlaves()
100100
$this->assertInternalType('array',$slaves);
101101
$this->assertCount(0,$slaves);
102102

103-
$this->expectException('CredisException','No such master with that name');
103+
$this->setExpectedExceptionShim('CredisException','No such master with that name');
104104
$this->sentinel->slaves('non-existing-cluster');
105105
}
106106
public function testNonExistingClusterNameWhenCreatingSlaves()
107107
{
108-
$this->expectException('CredisException','No such master with that name');
108+
$this->setExpectedExceptionShim('CredisException','No such master with that name');
109109
$this->sentinel->createSlaveClients('non-existing-cluster');
110110
}
111111
public function testCreateCluster()
@@ -116,7 +116,7 @@ public function testCreateCluster()
116116
$cluster = $this->sentinel->createCluster($this->sentinelConfig->clustername,0,1,false);
117117
$this->assertInstanceOf('Credis_Cluster',$cluster);
118118
$this->assertCount(2,$cluster->clients());
119-
$this->expectException('CredisException','The master is down');
119+
$this->setExpectedExceptionShim('CredisException','The master is down');
120120
$this->sentinel->createCluster($this->sentinelConfig->downclustername);
121121
}
122122
public function testGetCluster()
@@ -155,7 +155,7 @@ public function testGetHostAndPort()
155155
$host = 'localhost';
156156
$port = '123456';
157157

158-
$client = $this->createMock('\Credis_Client');
158+
$client = $this->createMockShim('\Credis_Client');
159159
$sentinel = new Credis_Sentinel($client);
160160

161161
$client->expects($this->once())->method('getHost')->willReturn($host);
@@ -166,7 +166,7 @@ public function testGetHostAndPort()
166166
}
167167
public function testNonExistingMethod()
168168
{
169-
$this->expectException('CredisException','Unknown sentinel subcommand \'bla\'');
169+
$this->setExpectedExceptionShim('CredisException','Unknown sentinel subcommand \'bla\'');
170170
$this->sentinel->bla();
171171
}
172172
}

tests/CredisStandaloneClusterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testMasterSlave()
2424
$this->waitForSlaveReplication();
2525
$this->assertEquals('value',$this->cluster->client('slave')->get('key'));
2626
$this->assertEquals('value',$this->cluster->get('key'));
27-
$this->expectException('CredisException','READONLY You can\'t write against a read only slave.');
27+
$this->setExpectedExceptionShim('CredisException','READONLY You can\'t write against a read only slave.');
2828
$this->cluster->client('slave')->set('key2','value');
2929
}
3030
}

tests/CredisStandaloneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testStandAloneArgumentsExtra()
3838

3939
public function testStandAloneMultiPipelineThrowsException()
4040
{
41-
$this->expectException('CredisException','A pipeline is already in use and only one pipeline is supported.');
41+
$this->setExpectedExceptionShim('CredisException','A pipeline is already in use and only one pipeline is supported.');
4242
$this->credis->pipeline()->pipeline();
4343
}
4444
}

tests/CredisTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ public function testGettersAndSetters()
622622
$this->credis->forceStandalone();
623623
}
624624
$this->credis->setMaxConnectRetries(1);
625-
$this->expectException('CredisException','Connection to Redis localhost:12345 failed after 2 failures.');
625+
$this->setExpectedExceptionShim('CredisException','Connection to Redis localhost:12345 failed after 2 failures.');
626626
$this->credis->connect();
627627
}
628628

@@ -664,7 +664,7 @@ public function testConnectionStringsSocket()
664664
public function testInvalidTcpConnectionstring()
665665
{
666666
$this->credis->close();
667-
$this->expectException('CredisException','Invalid host format; expected tcp://host[:port][/persistence_identifier]');
667+
$this->setExpectedExceptionShim('CredisException','Invalid host format; expected tcp://host[:port][/persistence_identifier]');
668668
$this->credis = new Credis_Client('tcp://'.$this->redisConfig[0]['host'] . ':abc');
669669
if ($this->useStandalone) {
670670
$this->credis->forceStandalone();
@@ -674,7 +674,7 @@ public function testInvalidTcpConnectionstring()
674674
public function testInvalidUnixSocketConnectionstring()
675675
{
676676
$this->credis->close();
677-
$this->expectException('CredisException','Invalid unix socket format; expected unix:///path/to/redis.sock');
677+
$this->setExpectedExceptionShim('CredisException','Invalid unix socket format; expected unix:///path/to/redis.sock');
678678
$this->credis = new Credis_Client('unix://path/to/redis.sock');
679679
if ($this->useStandalone) {
680680
$this->credis->forceStandalone();
@@ -685,7 +685,7 @@ public function testForceStandAloneAfterEstablishedConnection()
685685
{
686686
$this->credis->connect();
687687
if ( ! $this->useStandalone) {
688-
$this->expectException('CredisException','Cannot force Credis_Client to use standalone PHP driver after a connection has already been established.');
688+
$this->setExpectedExceptionShim('CredisException','Cannot force Credis_Client to use standalone PHP driver after a connection has already been established.');
689689
}
690690
$this->credis->forceStandalone();
691691
$this->assertTrue(true);

tests/CredisTestCommon.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,29 @@ public static function tearDownAfterClass()
150150
@copy('redis-sentinel.conf.bak','redis-sentinel.conf');
151151
}
152152
}
153-
153+
154+
155+
//
154156
/**
157+
* php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue
158+
* This is due to the defined return type
159+
*
155160
* Polyfill for older PHPUnit
156161
*/
157-
public function createMock($class)
162+
protected function createMockShim($originalClassName)
158163
{
159164
if (method_exists($this, 'getMock')) {
160-
return $this->getMock($class);
165+
return $this->getMock($originalClassName);
161166
} else {
162-
return parent::createMock($class);
167+
return parent::createMock($originalClassName);
163168
}
164169
}
165-
170+
166171
/**
167-
* Polyfill for older PHPUnit
172+
* php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue
173+
* This is due to the defined return type
168174
*/
169-
public function expectException($class, $message = NULL, $code = NULL)
175+
public function setExpectedExceptionShim($class, $message = NULL, $code = NULL)
170176
{
171177
if (method_exists($this, 'setExpectedException')) {
172178
$this->setExpectedException($class, $message, $code);

0 commit comments

Comments
 (0)