RedisClusterTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Connection;
  11. use PHPUnit_Framework_TestCase as StandardTestCase;
  12. use Predis\Profile;
  13. use Predis\Response;
  14. /**
  15. *
  16. */
  17. class RedisClusterTest extends StandardTestCase
  18. {
  19. /**
  20. * @group disconnected
  21. */
  22. public function testExposesCommandHashStrategy()
  23. {
  24. $cluster = new RedisCluster();
  25. $this->assertInstanceOf('Predis\Cluster\RedisStrategy', $cluster->getClusterStrategy());
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testAddingConnectionsToCluster()
  31. {
  32. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  33. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  34. $cluster = new RedisCluster();
  35. $cluster->add($connection1);
  36. $cluster->add($connection2);
  37. $this->assertSame(2, count($cluster));
  38. $this->assertSame($connection1, $cluster->getConnectionById('127.0.0.1:6379'));
  39. $this->assertSame($connection2, $cluster->getConnectionById('127.0.0.1:6380'));
  40. }
  41. /**
  42. * @group disconnected
  43. */
  44. public function testRemovingConnectionsFromCluster()
  45. {
  46. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  47. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  48. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6371');
  49. $cluster = new RedisCluster();
  50. $cluster->add($connection1);
  51. $cluster->add($connection2);
  52. $this->assertTrue($cluster->remove($connection1));
  53. $this->assertFalse($cluster->remove($connection3));
  54. $this->assertSame(1, count($cluster));
  55. }
  56. /**
  57. * @group disconnected
  58. */
  59. public function testRemovingConnectionsFromClusterByAlias()
  60. {
  61. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  62. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  63. $cluster = new RedisCluster();
  64. $cluster->add($connection1);
  65. $cluster->add($connection2);
  66. $this->assertTrue($cluster->removeById('127.0.0.1:6380'));
  67. $this->assertFalse($cluster->removeById('127.0.0.1:6390'));
  68. $this->assertSame(1, count($cluster));
  69. }
  70. /**
  71. * @group disconnected
  72. */
  73. public function testCountReturnsNumberOfConnectionsInPool()
  74. {
  75. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  76. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  77. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  78. $cluster = new RedisCluster();
  79. $cluster->add($connection1);
  80. $cluster->add($connection2);
  81. $cluster->add($connection3);
  82. $this->assertSame(3, count($cluster));
  83. $cluster->remove($connection3);
  84. $this->assertSame(2, count($cluster));
  85. }
  86. /**
  87. * @group disconnected
  88. */
  89. public function testConnectForcesAllConnectionsToConnect()
  90. {
  91. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  92. $connection1->expects($this->once())->method('connect');
  93. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  94. $connection2->expects($this->once())->method('connect');
  95. $cluster = new RedisCluster();
  96. $cluster->add($connection1);
  97. $cluster->add($connection2);
  98. $cluster->connect();
  99. }
  100. /**
  101. * @group disconnected
  102. */
  103. public function testDisconnectForcesAllConnectionsToDisconnect()
  104. {
  105. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  106. $connection1->expects($this->once())->method('disconnect');
  107. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  108. $connection2->expects($this->once())->method('disconnect');
  109. $cluster = new RedisCluster();
  110. $cluster->add($connection1);
  111. $cluster->add($connection2);
  112. $cluster->disconnect();
  113. }
  114. /**
  115. * @group disconnected
  116. */
  117. public function testIsConnectedReturnsTrueIfAtLeastOneConnectionIsOpen()
  118. {
  119. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  120. $connection1->expects($this->once())
  121. ->method('isConnected')
  122. ->will($this->returnValue(false));
  123. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  124. $connection2->expects($this->once())
  125. ->method('isConnected')
  126. ->will($this->returnValue(true));
  127. $cluster = new RedisCluster();
  128. $cluster->add($connection1);
  129. $cluster->add($connection2);
  130. $this->assertTrue($cluster->isConnected());
  131. }
  132. /**
  133. * @group disconnected
  134. */
  135. public function testIsConnectedReturnsFalseIfAllConnectionsAreClosed()
  136. {
  137. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  138. $connection1->expects($this->once())
  139. ->method('isConnected')
  140. ->will($this->returnValue(false));
  141. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  142. $connection2->expects($this->once())
  143. ->method('isConnected')
  144. ->will($this->returnValue(false));
  145. $cluster = new RedisCluster();
  146. $cluster->add($connection1);
  147. $cluster->add($connection2);
  148. $this->assertFalse($cluster->isConnected());
  149. }
  150. /**
  151. * @group disconnected
  152. */
  153. public function testCanReturnAnIteratorForConnections()
  154. {
  155. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  156. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  157. $cluster = new RedisCluster();
  158. $cluster->add($connection1);
  159. $cluster->add($connection2);
  160. $this->assertInstanceOf('Iterator', $iterator = $cluster->getIterator());
  161. $connections = iterator_to_array($iterator);
  162. $this->assertSame($connection1, $connections[0]);
  163. $this->assertSame($connection2, $connections[1]);
  164. }
  165. /**
  166. * @group disconnected
  167. */
  168. public function testCanAssignConnectionsToCustomSlots()
  169. {
  170. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  171. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  172. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  173. $cluster = new RedisCluster();
  174. $cluster->add($connection1);
  175. $cluster->add($connection2);
  176. $cluster->add($connection3);
  177. $cluster->setSlots(0, 1364, '127.0.0.1:6379');
  178. $cluster->setSlots(1365, 2729, '127.0.0.1:6380');
  179. $cluster->setSlots(2730, 4095, '127.0.0.1:6381');
  180. $expectedMap = array_merge(
  181. array_fill(0, 1365, '127.0.0.1:6379'),
  182. array_fill(1364, 1365, '127.0.0.1:6380'),
  183. array_fill(2729, 1366, '127.0.0.1:6381')
  184. );
  185. $this->assertSame($expectedMap, $cluster->getSlotsMap());
  186. }
  187. /**
  188. * @group disconnected
  189. */
  190. public function testAddingConnectionResetsSlotsMap()
  191. {
  192. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  193. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  194. $cluster = new RedisCluster();
  195. $cluster->add($connection1);
  196. $cluster->setSlots(0, 4095, '127.0.0.1:6379');
  197. $this->assertSame(array_fill(0, 4096, '127.0.0.1:6379'), $cluster->getSlotsMap());
  198. $cluster->add($connection2);
  199. $this->assertEmpty($cluster->getSlotsMap());
  200. }
  201. /**
  202. * @group disconnected
  203. */
  204. public function testRemovingConnectionResetsSlotsMap()
  205. {
  206. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  207. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  208. $cluster = new RedisCluster();
  209. $cluster->add($connection1);
  210. $cluster->add($connection2);
  211. $cluster->setSlots(0, 2047, '127.0.0.1:6379');
  212. $cluster->setSlots(2048, 4095, '127.0.0.1:6380');
  213. $expectedMap = array_merge(
  214. array_fill(0, 2048, '127.0.0.1:6379'),
  215. array_fill(2048, 2048, '127.0.0.1:6380')
  216. );
  217. $this->assertSame($expectedMap, $cluster->getSlotsMap());
  218. $cluster->remove($connection1);
  219. $this->assertEmpty($cluster->getSlotsMap());
  220. }
  221. /**
  222. * @group disconnected
  223. */
  224. public function testCanAssignConnectionsToCustomSlotsFromParameters()
  225. {
  226. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-5460');
  227. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-10921');
  228. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10922-16383');
  229. $cluster = new RedisCluster();
  230. $cluster->add($connection1);
  231. $cluster->add($connection2);
  232. $cluster->add($connection3);
  233. $expectedMap = array_merge(
  234. array_fill(0, 5461, '127.0.0.1:6379'),
  235. array_fill(5460, 5461, '127.0.0.1:6380'),
  236. array_fill(10921, 5462, '127.0.0.1:6381')
  237. );
  238. $cluster->buildSlotsMap();
  239. $this->assertSame($expectedMap, $cluster->getSlotsMap());
  240. }
  241. /**
  242. * @group disconnected
  243. */
  244. public function testReturnsCorrectConnectionUsingSlotID()
  245. {
  246. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  247. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  248. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  249. $cluster = new RedisCluster();
  250. $cluster->add($connection1);
  251. $cluster->add($connection2);
  252. $cluster->add($connection3);
  253. $this->assertSame($connection1, $cluster->getConnectionBySlot(0));
  254. $this->assertSame($connection2, $cluster->getConnectionBySlot(5461));
  255. $this->assertSame($connection3, $cluster->getConnectionBySlot(10922));
  256. $cluster->setSlots(5461, 7096, '127.0.0.1:6380');
  257. $this->assertSame($connection2, $cluster->getConnectionBySlot(5461));
  258. }
  259. /**
  260. * @group disconnected
  261. */
  262. public function testReturnsCorrectConnectionUsingCommandInstance()
  263. {
  264. $profile = Profile\Factory::getDefault();
  265. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  266. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  267. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  268. $cluster = new RedisCluster();
  269. $cluster->add($connection1);
  270. $cluster->add($connection2);
  271. $cluster->add($connection3);
  272. $set = $profile->createCommand('set', array('node:1001', 'foobar'));
  273. $get = $profile->createCommand('get', array('node:1001'));
  274. $this->assertSame($connection1, $cluster->getConnection($set));
  275. $this->assertSame($connection1, $cluster->getConnection($get));
  276. $set = $profile->createCommand('set', array('node:1048', 'foobar'));
  277. $get = $profile->createCommand('get', array('node:1048'));
  278. $this->assertSame($connection2, $cluster->getConnection($set));
  279. $this->assertSame($connection2, $cluster->getConnection($get));
  280. $set = $profile->createCommand('set', array('node:1082', 'foobar'));
  281. $get = $profile->createCommand('get', array('node:1082'));
  282. $this->assertSame($connection3, $cluster->getConnection($set));
  283. $this->assertSame($connection3, $cluster->getConnection($get));
  284. }
  285. /**
  286. * @group disconnected
  287. */
  288. public function testWritesCommandToCorrectConnection()
  289. {
  290. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
  291. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  292. $connection1->expects($this->once())->method('writeCommand')->with($command);
  293. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  294. $connection2->expects($this->never())->method('writeCommand');
  295. $cluster = new RedisCluster();
  296. $cluster->add($connection1);
  297. $cluster->add($connection2);
  298. $cluster->writeCommand($command);
  299. }
  300. /**
  301. * @group disconnected
  302. */
  303. public function testReadsCommandFromCorrectConnection()
  304. {
  305. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1050'));
  306. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  307. $connection1->expects($this->never())->method('readResponse');
  308. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  309. $connection2->expects($this->once())->method('readResponse')->with($command);
  310. $cluster = new RedisCluster();
  311. $cluster->add($connection1);
  312. $cluster->add($connection2);
  313. $cluster->readResponse($command);
  314. }
  315. /**
  316. * @group disconnected
  317. */
  318. public function testDoesNotSupportKeyTags()
  319. {
  320. $profile = Profile\Factory::getDefault();
  321. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  322. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  323. $cluster = new RedisCluster();
  324. $cluster->add($connection1);
  325. $cluster->add($connection2);
  326. $set = $profile->createCommand('set', array('{node:1001}:foo', 'foobar'));
  327. $get = $profile->createCommand('get', array('{node:1001}:foo'));
  328. $this->assertSame($connection1, $cluster->getConnection($set));
  329. $this->assertSame($connection1, $cluster->getConnection($get));
  330. $set = $profile->createCommand('set', array('{node:1001}:bar', 'foobar'));
  331. $get = $profile->createCommand('get', array('{node:1001}:bar'));
  332. $this->assertSame($connection2, $cluster->getConnection($set));
  333. $this->assertSame($connection2, $cluster->getConnection($get));
  334. }
  335. /**
  336. * @group disconnected
  337. */
  338. public function testAskResponseWithConnectionInPool()
  339. {
  340. $askResponse = new Response\Error('ASK 1970 127.0.0.1:6380');
  341. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
  342. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  343. $connection1->expects($this->exactly(2))
  344. ->method('executeCommand')
  345. ->with($command)
  346. ->will($this->onConsecutiveCalls($askResponse, 'foobar'));
  347. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  348. $connection2->expects($this->at(2))
  349. ->method('executeCommand')
  350. ->with($this->isRedisCommand('ASKING'));
  351. $connection2->expects($this->at(3))
  352. ->method('executeCommand')
  353. ->with($command)
  354. ->will($this->returnValue('foobar'));
  355. $factory = $this->getMock('Predis\Connection\ConnectionFactory');
  356. $factory->expects($this->never())->method('create');
  357. $cluster = new RedisCluster($factory);
  358. $cluster->add($connection1);
  359. $cluster->add($connection2);
  360. $this->assertSame('foobar', $cluster->executeCommand($command));
  361. $this->assertSame('foobar', $cluster->executeCommand($command));
  362. $this->assertSame(2, count($cluster));
  363. }
  364. /**
  365. * @group disconnected
  366. */
  367. public function testAskResponseWithConnectionNotInPool()
  368. {
  369. $askResponse = new Response\Error('ASK 1970 127.0.0.1:6381');
  370. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
  371. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  372. $connection1->expects($this->exactly(2))
  373. ->method('executeCommand')
  374. ->with($command)
  375. ->will($this->onConsecutiveCalls($askResponse, 'foobar'));
  376. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  377. $connection2->expects($this->never())
  378. ->method('executeCommand');
  379. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  380. $connection3->expects($this->at(0))
  381. ->method('executeCommand')
  382. ->with($this->isRedisCommand('ASKING'));
  383. $connection3->expects($this->at(1))
  384. ->method('executeCommand')
  385. ->with($command)
  386. ->will($this->returnValue('foobar'));
  387. $factory = $this->getMock('Predis\Connection\ConnectionFactory');
  388. $factory->expects($this->once())
  389. ->method('create')
  390. ->with(array('host' => '127.0.0.1', 'port' => '6381'))
  391. ->will($this->returnValue($connection3));
  392. $cluster = new RedisCluster($factory);
  393. $cluster->add($connection1);
  394. $cluster->add($connection2);
  395. $this->assertSame('foobar', $cluster->executeCommand($command));
  396. $this->assertSame('foobar', $cluster->executeCommand($command));
  397. $this->assertSame(2, count($cluster));
  398. }
  399. /**
  400. * @group disconnected
  401. */
  402. public function testMovedResponseWithConnectionInPool()
  403. {
  404. $movedResponse = new Response\Error('MOVED 1970 127.0.0.1:6380');
  405. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
  406. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  407. $connection1->expects($this->exactly(1))
  408. ->method('executeCommand')
  409. ->with($command)
  410. ->will($this->returnValue($movedResponse));
  411. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  412. $connection2->expects($this->exactly(2))
  413. ->method('executeCommand')
  414. ->with($command)
  415. ->will($this->onConsecutiveCalls('foobar', 'foobar'));
  416. $factory = $this->getMock('Predis\Connection\ConnectionFactory');
  417. $factory->expects($this->never())->method('create');
  418. $cluster = new RedisCluster($factory);
  419. $cluster->add($connection1);
  420. $cluster->add($connection2);
  421. $this->assertSame('foobar', $cluster->executeCommand($command));
  422. $this->assertSame('foobar', $cluster->executeCommand($command));
  423. $this->assertSame(2, count($cluster));
  424. }
  425. /**
  426. * @group disconnected
  427. */
  428. public function testMovedResponseWithConnectionNotInPool()
  429. {
  430. $movedResponse = new Response\Error('MOVED 1970 127.0.0.1:6381');
  431. $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
  432. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
  433. $connection1->expects($this->once())
  434. ->method('executeCommand')
  435. ->with($command)
  436. ->will($this->returnValue($movedResponse));
  437. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
  438. $connection2->expects($this->never())
  439. ->method('executeCommand');
  440. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381');
  441. $connection3->expects($this->exactly(2))
  442. ->method('executeCommand')
  443. ->with($command)
  444. ->will($this->onConsecutiveCalls('foobar', 'foobar'));
  445. $factory = $this->getMock('Predis\Connection\ConnectionFactory');
  446. $factory->expects($this->once())
  447. ->method('create')
  448. ->with(array('host' => '127.0.0.1', 'port' => '6381'))
  449. ->will($this->returnValue($connection3));
  450. $cluster = new RedisCluster($factory);
  451. $cluster->add($connection1);
  452. $cluster->add($connection2);
  453. $this->assertSame('foobar', $cluster->executeCommand($command));
  454. $this->assertSame('foobar', $cluster->executeCommand($command));
  455. $this->assertSame(3, count($cluster));
  456. }
  457. /**
  458. * @group disconnected
  459. * @expectedException Predis\NotSupportedException
  460. * @expectedExceptionMessage Cannot use PING with redis-cluster
  461. */
  462. public function testThrowsExceptionOnNonSupportedCommand()
  463. {
  464. $ping = Profile\Factory::getDefault()->createCommand('ping');
  465. $cluster = new RedisCluster();
  466. $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379'));
  467. $cluster->getConnection($ping);
  468. }
  469. /**
  470. * @group disconnected
  471. */
  472. public function testCanBeSerialized()
  473. {
  474. $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-1364');
  475. $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=1365-2729');
  476. $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=2730-4095');
  477. $cluster = new RedisCluster();
  478. $cluster->add($connection1);
  479. $cluster->add($connection2);
  480. $cluster->add($connection3);
  481. $cluster->buildSlotsMap();
  482. $unserialized = unserialize(serialize($cluster));
  483. $this->assertEquals($cluster, $unserialized);
  484. }
  485. // ******************************************************************** //
  486. // ---- HELPER METHODS ------------------------------------------------ //
  487. // ******************************************************************** //
  488. /**
  489. * Asserts that two arrays have the same values, even if with different order.
  490. *
  491. * @param string|CommandInterface $command Expected command or command ID.
  492. * @param array $arguments Expected command arguments.
  493. */
  494. protected function isRedisCommand($command = null, array $arguments = null)
  495. {
  496. return new \RedisCommandConstraint($command, $arguments);
  497. }
  498. /**
  499. * Returns a base mocked connection from Predis\Connection\SingleConnectionInterface.
  500. *
  501. * @param mixed $parameters Optional parameters.
  502. * @return mixed
  503. */
  504. protected function getMockConnection($parameters = null)
  505. {
  506. $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
  507. if ($parameters) {
  508. $parameters = new ConnectionParameters($parameters);
  509. $hash = "{$parameters->host}:{$parameters->port}";
  510. $connection->expects($this->any())
  511. ->method('getParameters')
  512. ->will($this->returnValue($parameters));
  513. $connection->expects($this->any())
  514. ->method('__toString')
  515. ->will($this->returnValue($hash));
  516. }
  517. return $connection;
  518. }
  519. }