mirror of
https://github.com/predis/predis.git
synced 2026-10-06 03:47:57 +00:00
[tests] Replace deprecated TestCase::at().
The "at" matcher will be removed in PHPUnit 10 but it is not a bad thing after all because it was cumbersome and error-prone. Took the opportunity to improve some tests while converting them.
This commit is contained in:
@@ -466,12 +466,12 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
{
|
||||
$sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
||||
$sentinel1
|
||||
->expects($this->at(0))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SENTINEL', array('get-master-addr-by-name', 'svc')
|
||||
))
|
||||
->willReturn(
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('127.0.0.1', '6381')
|
||||
);
|
||||
|
||||
@@ -511,12 +511,12 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
{
|
||||
$sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
||||
$sentinel1
|
||||
->expects($this->at(0))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SENTINEL', array('slaves', 'svc')
|
||||
))
|
||||
->willReturn(
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('SENTINEL', array('slaves', 'svc')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
array(
|
||||
'name', '127.0.0.1:6382',
|
||||
@@ -670,21 +670,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
{
|
||||
$sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
||||
$sentinel1
|
||||
->expects($this->at(0))
|
||||
->expects($this->exactly(2))
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SENTINEL', array('slaves', 'svc')
|
||||
))
|
||||
->willReturn(
|
||||
array()
|
||||
);
|
||||
$sentinel1
|
||||
->expects($this->at(1))
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SENTINEL', array('get-master-addr-by-name', 'svc')
|
||||
))
|
||||
->willReturn(
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('SENTINEL', array('slaves', 'svc'))),
|
||||
array($this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(),
|
||||
array('127.0.0.1', '6381')
|
||||
);
|
||||
|
||||
@@ -912,12 +905,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturnOnConsecutiveCalls(false, true);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'master', 3129659, array(array('127.0.0.1', 6382, 3129242)),
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('master', 3129659, array(array('127.0.0.1', 6382, 3129242)))
|
||||
);
|
||||
|
||||
$slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
||||
|
||||
@@ -950,12 +945,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturnOnConsecutiveCalls(false, true);
|
||||
$slave1
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'slave', '127.0.0.1', 9000, 'connected', 3167038,
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('slave', '127.0.0.1', 9000, 'connected', 3167038)
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
||||
|
||||
@@ -984,25 +981,29 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturnOnConsecutiveCalls(false, true);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'master', 3129659, array(array('127.0.0.1', 6382, 3129242)),
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('master', 3129659, array(array('127.0.0.1', 6382, 3129242)))
|
||||
);
|
||||
|
||||
$slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
||||
$slave1
|
||||
->expects($this->exactly(1))
|
||||
->expects($this->once())
|
||||
->method('isConnected')
|
||||
->willReturnOnConsecutiveCalls(false);
|
||||
$slave1
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'slave', '127.0.0.1', 9000, 'connected', 3167038,
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('slave', '127.0.0.1', 9000, 'connected', 3167038)
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
||||
|
||||
@@ -1038,12 +1039,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(false);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'slave', '127.0.0.1', 9000, 'connected', 3167038,
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('slave', '127.0.0.1', 9000, 'connected', 3167038)
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
||||
|
||||
@@ -1061,10 +1064,10 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
$sentinel1
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SENTINEL', array('slaves', 'svc')
|
||||
))
|
||||
->willReturn(
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('SENTINEL', array('slaves', 'svc')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
array(
|
||||
'name', '127.0.0.1:6382',
|
||||
@@ -1084,12 +1087,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(false);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand('ROLE'))
|
||||
->willReturn(array(
|
||||
'master', '0', array(),
|
||||
));
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('ROLE'))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array('master', '0', array())
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
||||
|
||||
@@ -1117,12 +1122,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'SET', array('key', $cmdGetResponse)
|
||||
))
|
||||
->willReturn($cmdSetResponse);
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('SET', array('key', $cmdGetResponse)))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$cmdSetResponse
|
||||
);
|
||||
|
||||
$slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
||||
$slave1
|
||||
@@ -1130,12 +1137,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$slave1
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'GET', array('key')
|
||||
))
|
||||
->willReturn($cmdGetResponse);
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('GET', array('key')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$cmdGetResponse
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
||||
|
||||
@@ -1184,11 +1193,11 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$slave1
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'GET', array('key')
|
||||
))
|
||||
->with(
|
||||
$this->isRedisCommand('GET', array('key'))
|
||||
)
|
||||
->willThrowException(
|
||||
new Connection\ConnectionException($slave1, 'Unknown connection error [127.0.0.1:6382]')
|
||||
);
|
||||
@@ -1199,12 +1208,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$slave2
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'GET', array('key')
|
||||
))
|
||||
->willReturn('value');
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('GET', array('key')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'value'
|
||||
);
|
||||
|
||||
/** @var Connection\FactoryInterface|MockObject */
|
||||
$factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock();
|
||||
@@ -1250,11 +1261,11 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$masterOld
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'DEL', array('key')
|
||||
))
|
||||
->with(
|
||||
$this->isRedisCommand('DEL', array('key'))
|
||||
)
|
||||
->willThrowException(
|
||||
new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]')
|
||||
);
|
||||
@@ -1265,12 +1276,14 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$masterNew
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'DEL', array('key')
|
||||
))
|
||||
->willReturn(1);
|
||||
->withConsecutive(
|
||||
array($this->isRedisCommand('DEL', array('key')))
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
1
|
||||
);
|
||||
|
||||
/** @var Connection\FactoryInterface|MockObject */
|
||||
$factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock();
|
||||
@@ -1316,11 +1329,11 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$masterOld
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'DEL', array('key')
|
||||
))
|
||||
->with(
|
||||
$this->isRedisCommand('DEL', array('key'))
|
||||
)
|
||||
->willThrowException(
|
||||
new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]')
|
||||
);
|
||||
@@ -1359,11 +1372,11 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
->method('isConnected')
|
||||
->willReturn(true);
|
||||
$master
|
||||
->expects($this->at(3))
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isRedisCommand(
|
||||
'DEL', array('key')
|
||||
))
|
||||
->with(
|
||||
$this->isRedisCommand('DEL', array('key'))
|
||||
)
|
||||
->willThrowException(
|
||||
new Connection\ConnectionException($master, 'Unknown connection error [127.0.0.1:6381]')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user