PhpiredisSocketConnectionTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Predis\Command\RawCommand;
  12. use Predis\Response\Error as ErrorResponse;
  13. /**
  14. * @group ext-phpiredis
  15. * @requires extension phpiredis
  16. */
  17. class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
  18. {
  19. const CONNECTION_CLASS = 'Predis\Connection\PhpiredisSocketConnection';
  20. /**
  21. * @group disconnected
  22. * @expectedException \InvalidArgumentException
  23. * @expectedExceptionMessage Invalid scheme: 'tls'.
  24. */
  25. public function testSupportsSchemeTls()
  26. {
  27. $connection = $this->createConnectionWithParams(array('scheme' => 'tls'));
  28. $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
  29. }
  30. /**
  31. * @group disconnected
  32. * @expectedException \InvalidArgumentException
  33. * @expectedExceptionMessage Invalid scheme: 'rediss'.
  34. */
  35. public function testSupportsSchemeRediss()
  36. {
  37. $connection = $this->createConnectionWithParams(array('scheme' => 'rediss'));
  38. $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
  39. }
  40. /**
  41. * @group disconnected
  42. * @expectedException \Predis\Connection\ConnectionException
  43. * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]
  44. */
  45. public function testThrowsExceptionOnInitializationCommandFailure()
  46. {
  47. $cmdSelect = RawCommand::create('SELECT', '1000');
  48. $connection = $this
  49. ->getMockBuilder(static::CONNECTION_CLASS)
  50. ->setMethods(array('executeCommand', 'createResource'))
  51. ->setConstructorArgs(array(new Parameters()))
  52. ->getMock();
  53. $connection
  54. ->method('executeCommand')
  55. ->with($cmdSelect)
  56. ->will($this->returnValue(
  57. new ErrorResponse('ERR invalid DB index')
  58. ));
  59. $connection->method('createResource');
  60. $connection->addConnectCommand($cmdSelect);
  61. $connection->connect();
  62. }
  63. // ******************************************************************** //
  64. // ---- INTEGRATION TESTS --------------------------------------------- //
  65. // ******************************************************************** //
  66. /**
  67. * @group connected
  68. * @expectedException \Predis\Connection\ConnectionException
  69. * @expectedExceptionMessage Cannot resolve the address of 'bogus.tld'.
  70. */
  71. public function testThrowsExceptionOnUnresolvableHostname()
  72. {
  73. $connection = $this->createConnectionWithParams(array('host' => 'bogus.tld'));
  74. $connection->connect();
  75. }
  76. /**
  77. * @medium
  78. * @group connected
  79. * @expectedException \Predis\Protocol\ProtocolException
  80. */
  81. public function testThrowsExceptionOnProtocolDesynchronizationErrors()
  82. {
  83. $connection = $this->createConnection();
  84. $socket = $connection->getResource();
  85. $connection->writeRequest($this->getCommandFactory()->createCommand('ping'));
  86. socket_read($socket, 1);
  87. $connection->read();
  88. }
  89. }