No Description

ExactValueTokenSpec.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace spec\Prophecy\Argument\Token;
  3. use PhpSpec\ObjectBehavior;
  4. class ExactValueTokenSpec extends ObjectBehavior
  5. {
  6. function let()
  7. {
  8. $this->beConstructedWith(42);
  9. }
  10. function it_implements_TokenInterface()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
  13. }
  14. function it_is_not_last()
  15. {
  16. $this->shouldNotBeLast();
  17. }
  18. function it_holds_value()
  19. {
  20. $this->getValue()->shouldReturn(42);
  21. }
  22. function it_scores_10_if_value_is_equal_to_argument()
  23. {
  24. $this->scoreArgument(42)->shouldReturn(10);
  25. $this->scoreArgument('42')->shouldReturn(10);
  26. }
  27. function it_scores_10_if_value_is_an_object_and_equal_to_argument()
  28. {
  29. $value = new \DateTime();
  30. $value2 = clone $value;
  31. $this->beConstructedWith($value);
  32. $this->scoreArgument($value2)->shouldReturn(10);
  33. }
  34. function it_does_not_scores_if_value_is_not_equal_to_argument()
  35. {
  36. $this->scoreArgument(50)->shouldReturn(false);
  37. $this->scoreArgument(new \stdClass())->shouldReturn(false);
  38. }
  39. function it_does_not_scores_if_value_an_object_and_is_not_equal_to_argument()
  40. {
  41. $value = new \stdClass();
  42. $value2 = new \stdClass();
  43. $value2->foo = 'bar';
  44. $this->beConstructedWith($value);
  45. $this->scoreArgument($value2)->shouldReturn(false);
  46. }
  47. function it_does_not_scores_if_value_type_and_is_not_equal_to_argument()
  48. {
  49. $this->beConstructedWith(false);
  50. $this->scoreArgument(0)->shouldReturn(false);
  51. }
  52. function it_generates_proper_string_representation_for_integer()
  53. {
  54. $this->beConstructedWith(42);
  55. $this->__toString()->shouldReturn('exact(42)');
  56. }
  57. function it_generates_proper_string_representation_for_string()
  58. {
  59. $this->beConstructedWith('some string');
  60. $this->__toString()->shouldReturn('exact("some string")');
  61. }
  62. function it_generates_single_line_representation_for_multiline_string()
  63. {
  64. $this->beConstructedWith("some\nstring");
  65. $this->__toString()->shouldReturn('exact("some\\nstring")');
  66. }
  67. function it_generates_proper_string_representation_for_double()
  68. {
  69. $this->beConstructedWith(42.3);
  70. $this->__toString()->shouldReturn('exact(42.3)');
  71. }
  72. function it_generates_proper_string_representation_for_boolean_true()
  73. {
  74. $this->beConstructedWith(true);
  75. $this->__toString()->shouldReturn('exact(true)');
  76. }
  77. function it_generates_proper_string_representation_for_boolean_false()
  78. {
  79. $this->beConstructedWith(false);
  80. $this->__toString()->shouldReturn('exact(false)');
  81. }
  82. function it_generates_proper_string_representation_for_null()
  83. {
  84. $this->beConstructedWith(null);
  85. $this->__toString()->shouldReturn('exact(null)');
  86. }
  87. function it_generates_proper_string_representation_for_empty_array()
  88. {
  89. $this->beConstructedWith(array());
  90. $this->__toString()->shouldReturn('exact([])');
  91. }
  92. function it_generates_proper_string_representation_for_array()
  93. {
  94. $this->beConstructedWith(array('zet', 42));
  95. $this->__toString()->shouldReturn('exact(["zet", 42])');
  96. }
  97. function it_generates_proper_string_representation_for_resource()
  98. {
  99. $resource = fopen(__FILE__, 'r');
  100. $this->beConstructedWith($resource);
  101. $this->__toString()->shouldReturn('exact(stream:'.$resource.')');
  102. }
  103. /**
  104. * @param \stdClass $object
  105. */
  106. function it_generates_proper_string_representation_for_object($object)
  107. {
  108. $objHash = sprintf('%s:%s',
  109. get_class($object->getWrappedObject()),
  110. spl_object_hash($object->getWrappedObject())
  111. );
  112. $this->beConstructedWith($object);
  113. $this->__toString()->shouldReturn("exact($objHash Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n))");
  114. }
  115. }