HelpersTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class HelpersTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testOnCommunicationException()
  21. {
  22. $this->setExpectedException('Predis\CommunicationException');
  23. $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
  24. $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
  25. $connection->expects($this->once())->method('disconnect');
  26. $exception = $this->getMockForAbstractClass('Predis\CommunicationException', array($connection));
  27. Helpers::onCommunicationException($exception);
  28. }
  29. /**
  30. * @group disconnected
  31. */
  32. public function testFilterArrayArguments()
  33. {
  34. $arguments = array('arg1', 'arg2', 'arg3', 'arg4');
  35. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  36. $this->assertSame($arguments, Helpers::filterArrayArguments(array($arguments)));
  37. $arguments = array(array(), array());
  38. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  39. $arguments = array(new \stdClass());
  40. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  41. }
  42. /**
  43. * @group disconnected
  44. */
  45. public function testFilterVariadicValues()
  46. {
  47. $arguments = array('key', 'value1', 'value2', 'value3');
  48. $this->assertSame($arguments, Helpers::filterVariadicValues($arguments));
  49. $this->assertSame($arguments, Helpers::filterVariadicValues(array('key', array('value1', 'value2', 'value3'))));
  50. $arguments = array(array(), array());
  51. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  52. $arguments = array(new \stdClass());
  53. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  54. }
  55. }