PrefixHelpersTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\Commands;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class PrefixHelpersTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testPrefixFirst()
  21. {
  22. $arguments = array('1st', '2nd', '3rd', '4th');
  23. $expected = array('prefix:1st', '2nd', '3rd', '4th');
  24. $command = $this->getMockForAbstractClass('Predis\Commands\Command');
  25. $command->setRawArguments($arguments);
  26. PrefixHelpers::first($command, 'prefix:');
  27. $this->assertSame($expected, $command->getArguments());
  28. }
  29. /**
  30. * @group disconnected
  31. */
  32. public function testPrefixAll()
  33. {
  34. $arguments = array('1st', '2nd', '3rd', '4th');
  35. $expected = array('prefix:1st', 'prefix:2nd', 'prefix:3rd', 'prefix:4th');
  36. $command = $this->getMockForAbstractClass('Predis\Commands\Command');
  37. $command->setRawArguments($arguments);
  38. PrefixHelpers::all($command, 'prefix:');
  39. $this->assertSame($expected, $command->getArguments());
  40. }
  41. /**
  42. * @group disconnected
  43. */
  44. public function testPrefixInterleaved()
  45. {
  46. $arguments = array('1st', '2nd', '3rd', '4th');
  47. $expected = array('prefix:1st', '2nd', 'prefix:3rd', '4th');
  48. $command = $this->getMockForAbstractClass('Predis\Commands\Command');
  49. $command->setRawArguments($arguments);
  50. PrefixHelpers::interleaved($command, 'prefix:');
  51. $this->assertSame($expected, $command->getArguments());
  52. }
  53. /**
  54. * @group disconnected
  55. */
  56. public function testPrefixSkipLast()
  57. {
  58. $arguments = array('1st', '2nd', '3rd', '4th');
  59. $expected = array('prefix:1st', 'prefix:2nd', 'prefix:3rd', '4th');
  60. $command = $this->getMockForAbstractClass('Predis\Commands\Command');
  61. $command->setRawArguments($arguments);
  62. PrefixHelpers::skipLast($command, 'prefix:');
  63. $this->assertSame($expected, $command->getArguments());
  64. }
  65. }