HelpersTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class HelpersTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testConnectionIsCluster()
  21. {
  22. $single = $this->getMock('Predis\Network\IConnectionSingle');
  23. $cluster = $this->getMock('Predis\Network\IConnectionCluster');
  24. $this->assertFalse(Helpers::isCluster($single));
  25. $this->assertTrue(Helpers::isCluster($cluster));
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testOnCommunicationException()
  31. {
  32. $this->setExpectedException('Predis\CommunicationException');
  33. $connection = $this->getMock('Predis\Network\IConnectionSingle');
  34. $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
  35. $connection->expects($this->once())->method('disconnect');
  36. $exception = $this->getMockForAbstractClass('Predis\CommunicationException', array($connection));
  37. Helpers::onCommunicationException($exception);
  38. }
  39. /**
  40. * @group disconnected
  41. */
  42. public function testFilterArrayArguments()
  43. {
  44. $arguments = array('arg1', 'arg2', 'arg3', 'arg4');
  45. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  46. $this->assertSame($arguments, Helpers::filterArrayArguments(array($arguments)));
  47. $arguments = array(array(), array());
  48. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  49. $arguments = array(new \stdClass());
  50. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  51. }
  52. /**
  53. * @group disconnected
  54. */
  55. public function testFilterVariadicValues()
  56. {
  57. $arguments = array('key', 'value1', 'value2', 'value3');
  58. $this->assertSame($arguments, Helpers::filterVariadicValues($arguments));
  59. $this->assertSame($arguments, Helpers::filterVariadicValues(array('key', array('value1', 'value2', 'value3'))));
  60. $arguments = array(array(), array());
  61. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  62. $arguments = array(new \stdClass());
  63. $this->assertSame($arguments, Helpers::filterArrayArguments($arguments));
  64. }
  65. /**
  66. * @group disconnected
  67. */
  68. public function testExtractKeyTag()
  69. {
  70. $this->assertEquals('foo:bar', Helpers::extractKeyTag('foo:bar'));
  71. $this->assertEquals('foo:', Helpers::extractKeyTag('{foo:}bar'));
  72. $this->assertEquals('bar', Helpers::extractKeyTag('foo:{bar}'));
  73. $this->assertEquals('foo:bar', Helpers::extractKeyTag('{foo:bar}'));
  74. $this->assertEquals('', Helpers::extractKeyTag('foo{}:bar'));
  75. $this->assertEquals('', Helpers::extractKeyTag(''));
  76. $this->assertEquals('', Helpers::extractKeyTag('{}'));
  77. }
  78. }