PhpiredisStreamConnectionTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. * @group ext-phpiredis
  13. * @requires extension phpiredis
  14. */
  15. class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
  16. {
  17. const CONNECTION_CLASS = 'Predis\Connection\PhpiredisStreamConnection';
  18. /**
  19. * @group disconnected
  20. * @expectedException \InvalidArgumentException
  21. * @expectedExceptionMessage SSL encryption is not supported by this connection backend.
  22. */
  23. public function testSupportsSchemeTls()
  24. {
  25. $connection = $this->createConnectionWithParams(array('scheme' => 'tls'));
  26. $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
  27. }
  28. /**
  29. * @group disconnected
  30. * @expectedException \InvalidArgumentException
  31. * @expectedExceptionMessage SSL encryption is not supported by this connection backend.
  32. */
  33. public function testSupportsSchemeRediss()
  34. {
  35. $connection = $this->createConnectionWithParams(array('scheme' => 'rediss'));
  36. $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
  37. }
  38. // ******************************************************************** //
  39. // ---- INTEGRATION TESTS --------------------------------------------- //
  40. // ******************************************************************** //
  41. /**
  42. * @group connected
  43. * @group slow
  44. * @requires PHP 5.4
  45. * @expectedException \Predis\Connection\ConnectionException
  46. */
  47. public function testThrowsExceptionOnReadWriteTimeout()
  48. {
  49. $profile = $this->getCurrentProfile();
  50. $connection = $this->createConnectionWithParams(array(
  51. 'read_write_timeout' => 0.5,
  52. ), true);
  53. $connection->executeCommand($profile->createCommand('brpop', array('foo', 3)));
  54. }
  55. /**
  56. * @medium
  57. * @group connected
  58. * @expectedException \Predis\Protocol\ProtocolException
  59. */
  60. public function testThrowsExceptionOnProtocolDesynchronizationErrors()
  61. {
  62. $connection = $this->createConnection();
  63. $stream = $connection->getResource();
  64. $connection->writeRequest($this->getCurrentProfile()->createCommand('ping'));
  65. stream_socket_recvfrom($stream, 1);
  66. $connection->read();
  67. }
  68. /**
  69. * @group connected
  70. * @requires PHP 5.4
  71. */
  72. public function testPersistentParameterWithFalseLikeValues()
  73. {
  74. $connection1 = $this->createConnectionWithParams(array('persistent' => 0));
  75. $this->assertNonPersistentConnection($connection1);
  76. $connection2 = $this->createConnectionWithParams(array('persistent' => false));
  77. $this->assertNonPersistentConnection($connection2);
  78. $connection3 = $this->createConnectionWithParams(array('persistent' => '0'));
  79. $this->assertNonPersistentConnection($connection3);
  80. $connection4 = $this->createConnectionWithParams(array('persistent' => 'false'));
  81. $this->assertNonPersistentConnection($connection4);
  82. }
  83. /**
  84. * @group connected
  85. * @requires PHP 5.4
  86. */
  87. public function testPersistentParameterWithTrueLikeValues()
  88. {
  89. $connection1 = $this->createConnectionWithParams(array('persistent' => 1));
  90. $this->assertPersistentConnection($connection1);
  91. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  92. $this->assertPersistentConnection($connection2);
  93. $connection3 = $this->createConnectionWithParams(array('persistent' => '1'));
  94. $this->assertPersistentConnection($connection3);
  95. $connection4 = $this->createConnectionWithParams(array('persistent' => 'true'));
  96. $this->assertPersistentConnection($connection4);
  97. $connection1->disconnect();
  98. }
  99. /**
  100. * @group connected
  101. * @requires PHP 5.4
  102. */
  103. public function testPersistentConnectionsToSameNodeShareResource()
  104. {
  105. $connection1 = $this->createConnectionWithParams(array('persistent' => true));
  106. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  107. $this->assertPersistentConnection($connection1);
  108. $this->assertPersistentConnection($connection2);
  109. $this->assertSame($connection1->getResource(), $connection2->getResource());
  110. $connection1->disconnect();
  111. }
  112. /**
  113. * @group connected
  114. * @requires PHP 5.4
  115. */
  116. public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
  117. {
  118. $connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
  119. $connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));
  120. $this->assertPersistentConnection($connection1);
  121. $this->assertPersistentConnection($connection2);
  122. $this->assertNotSame($connection1->getResource(), $connection2->getResource());
  123. }
  124. }