CompositeStreamConnectionTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * @requires PHP 5.4
  36. */
  37. public function testPersistentParameterWithFalseLikeValues()
  38. {
  39. $connection1 = $this->createConnectionWithParams(array('persistent' => 0));
  40. $this->assertNonPersistentConnection($connection1);
  41. $connection2 = $this->createConnectionWithParams(array('persistent' => false));
  42. $this->assertNonPersistentConnection($connection2);
  43. $connection3 = $this->createConnectionWithParams(array('persistent' => '0'));
  44. $this->assertNonPersistentConnection($connection3);
  45. $connection4 = $this->createConnectionWithParams(array('persistent' => 'false'));
  46. $this->assertNonPersistentConnection($connection4);
  47. }
  48. /**
  49. * @group connected
  50. * @requires PHP 5.4
  51. */
  52. public function testPersistentParameterWithTrueLikeValues()
  53. {
  54. $connection1 = $this->createConnectionWithParams(array('persistent' => 1));
  55. $this->assertPersistentConnection($connection1);
  56. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  57. $this->assertPersistentConnection($connection2);
  58. $connection3 = $this->createConnectionWithParams(array('persistent' => '1'));
  59. $this->assertPersistentConnection($connection3);
  60. $connection4 = $this->createConnectionWithParams(array('persistent' => 'true'));
  61. $this->assertPersistentConnection($connection4);
  62. $connection1->disconnect();
  63. }
  64. /**
  65. * @group connected
  66. * @requires PHP 5.4
  67. */
  68. public function testPersistentConnectionsToSameNodeShareResource()
  69. {
  70. $connection1 = $this->createConnectionWithParams(array('persistent' => true));
  71. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  72. $this->assertPersistentConnection($connection1);
  73. $this->assertPersistentConnection($connection2);
  74. $this->assertSame($connection1->getResource(), $connection2->getResource());
  75. $connection1->disconnect();
  76. }
  77. /**
  78. * @group connected
  79. * @requires PHP 5.4
  80. */
  81. public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
  82. {
  83. $connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
  84. $connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));
  85. $this->assertPersistentConnection($connection1);
  86. $this->assertPersistentConnection($connection2);
  87. $this->assertNotSame($connection1->getResource(), $connection2->getResource());
  88. }
  89. }