AbstractOptionTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Option;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class AbstractOptionTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testValidationReturnsTheSameObject()
  21. {
  22. $value = new \stdClass();
  23. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  24. $option = $this->getMockForAbstractClass('Predis\Option\AbstractOption');
  25. $this->assertSame($value, $option->filter($options, $value));
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testDefaultReturnsNull()
  31. {
  32. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  33. $option = $this->getMockForAbstractClass('Predis\Option\AbstractOption');
  34. $this->assertNull($option->getDefault($options));
  35. }
  36. /**
  37. * @group disconnected
  38. */
  39. public function testInvokePerformsValidationWhenValueIsSet()
  40. {
  41. $value = new \stdClass();
  42. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  43. $option = $this->getMock('Predis\Option\AbstractOption', array('filter', 'getDefault'));
  44. $option->expects($this->once())
  45. ->method('filter')
  46. ->with($options, $value)
  47. ->will($this->returnValue($value));
  48. $option->expects($this->never())->method('getDefault');
  49. $this->assertSame($value, $option($options, $value));
  50. }
  51. /**
  52. * @group disconnected
  53. */
  54. public function testInvokeReturnsDefaultWhenValueIsNotSet()
  55. {
  56. $expected = new \stdClass();
  57. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  58. $option = $this->getMock('Predis\Option\AbstractOption', array('filter', 'getDefault'));
  59. $option->expects($this->never())->method('filter');
  60. $option->expects($this->once())
  61. ->method('getDefault')
  62. ->with($options)
  63. ->will($this->returnValue($expected));
  64. $this->assertSame($expected, $option($options, null));
  65. }
  66. }