CompositeStreamConnectionTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  12. *
  13. */
  14. class CompositeStreamConnectionTest extends PredisConnectionTestCase
  15. {
  16. const CONNECTION_CLASS = 'Predis\Connection\CompositeStreamConnection';
  17. // ******************************************************************** //
  18. // ---- INTEGRATION TESTS --------------------------------------------- //
  19. // ******************************************************************** //
  20. /**
  21. * @group connected
  22. */
  23. public function testReadsMultibulkResponsesAsIterators()
  24. {
  25. $connection = $this->createConnection(true);
  26. $profile = $this->getCurrentProfile();
  27. $connection->getProtocol()->useIterableMultibulk(true);
  28. $connection->executeCommand($profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')));
  29. $connection->writeRequest($profile->createCommand('lrange', array('metavars', 0, -1)));
  30. $this->assertInstanceOf('Predis\Response\Iterator\MultiBulkIterator', $iterator = $connection->read());
  31. $this->assertSame(array('foo', 'hoge', 'lol'), iterator_to_array($iterator));
  32. }
  33. /**
  34. * @group connected
  35. */
  36. public function testPersistentParameterWithFalseLikeValues()
  37. {
  38. if ($this->isHHVM()) {
  39. $this->markTestSkipped('This test does not currently work on HHVM.');
  40. }
  41. $connection1 = $this->createConnectionWithParams(array('persistent' => 0));
  42. $this->assertNonPersistentConnection($connection1);
  43. $connection2 = $this->createConnectionWithParams(array('persistent' => false));
  44. $this->assertNonPersistentConnection($connection2);
  45. $connection3 = $this->createConnectionWithParams(array('persistent' => '0'));
  46. $this->assertNonPersistentConnection($connection3);
  47. $connection4 = $this->createConnectionWithParams(array('persistent' => 'false'));
  48. $this->assertNonPersistentConnection($connection4);
  49. }
  50. /**
  51. * @group connected
  52. */
  53. public function testPersistentParameterWithTrueLikeValues()
  54. {
  55. if ($this->isHHVM()) {
  56. $this->markTestSkipped('This test does not currently work on HHVM.');
  57. }
  58. $connection1 = $this->createConnectionWithParams(array('persistent' => 1));
  59. $this->assertPersistentConnection($connection1);
  60. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  61. $this->assertPersistentConnection($connection2);
  62. $connection3 = $this->createConnectionWithParams(array('persistent' => '1'));
  63. $this->assertPersistentConnection($connection3);
  64. $connection4 = $this->createConnectionWithParams(array('persistent' => 'true'));
  65. $this->assertPersistentConnection($connection4);
  66. $connection1->disconnect();
  67. }
  68. /**
  69. * @group connected
  70. */
  71. public function testPersistentConnectionsToSameNodeShareResource()
  72. {
  73. if ($this->isHHVM()) {
  74. $this->markTestSkipped('This test does not currently work on HHVM.');
  75. }
  76. $connection1 = $this->createConnectionWithParams(array('persistent' => true));
  77. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  78. $this->assertPersistentConnection($connection1);
  79. $this->assertPersistentConnection($connection2);
  80. $this->assertSame($connection1->getResource(), $connection2->getResource());
  81. $connection1->disconnect();
  82. }
  83. /**
  84. * @group connected
  85. */
  86. public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
  87. {
  88. if ($this->isHHVM()) {
  89. $this->markTestSkipped('This test does not currently work on HHVM.');
  90. }
  91. $connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
  92. $connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));
  93. $this->assertPersistentConnection($connection1);
  94. $this->assertPersistentConnection($connection2);
  95. $this->assertNotSame($connection1->getResource(), $connection2->getResource());
  96. }
  97. }