EXEC_Test.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\Command\Redis;
  11. /**
  12. * @group commands
  13. * @group realm-transaction
  14. */
  15. class EXEC_Test extends PredisCommandTestCase
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getExpectedCommand()
  21. {
  22. return 'Predis\Command\Redis\EXEC';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function getExpectedId()
  28. {
  29. return 'EXEC';
  30. }
  31. /**
  32. * @group disconnected
  33. */
  34. public function testFilterArguments()
  35. {
  36. $command = $this->getCommand();
  37. $command->setArguments(array());
  38. $this->assertSame(array(), $command->getArguments());
  39. }
  40. /**
  41. * @group disconnected
  42. */
  43. public function testParseResponse()
  44. {
  45. $raw = array('tx1', 'tx2');
  46. $expected = array('tx1', 'tx2');
  47. $command = $this->getCommand();
  48. $this->assertSame($expected, $command->parseResponse($raw));
  49. }
  50. /**
  51. * @group connected
  52. */
  53. public function testExecutesTransactionAndReturnsArrayOfResponses()
  54. {
  55. $redis = $this->getClient();
  56. $redis->multi();
  57. $redis->echo('tx1');
  58. $redis->echo('tx2');
  59. $this->assertSame(array('tx1', 'tx2'), $redis->exec());
  60. }
  61. /**
  62. * @group connected
  63. */
  64. public function testReturnsEmptyArrayOnEmptyTransactions()
  65. {
  66. $redis = $this->getClient();
  67. $redis->multi();
  68. $this->assertSame(array(), $redis->exec());
  69. }
  70. /**
  71. * @group connected
  72. */
  73. public function testResponsesOfTransactionsAreNotParsed()
  74. {
  75. $redis = $this->getClient();
  76. $redis->multi();
  77. $redis->ping();
  78. $redis->set('foo', 'bar');
  79. $redis->exists('foo');
  80. $this->assertEquals(array('PONG', 'OK', 1), $redis->exec());
  81. }
  82. /**
  83. * @group connected
  84. * @expectedException \Predis\Response\ServerException
  85. * @expectedExceptionMessage ERR EXEC without MULTI
  86. */
  87. public function testThrowsExceptionWhenCallingOutsideTransaction()
  88. {
  89. $redis = $this->getClient();
  90. $redis->exec();
  91. }
  92. }