IdenticalValueTokenSpec.php 4.5 KB

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