ArgumentsWildcardSpec.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace spec\Prophecy\Argument;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument\Token\TokenInterface;
  5. class ArgumentsWildcardSpec extends ObjectBehavior
  6. {
  7. /**
  8. * @param \stdClass $object
  9. */
  10. function it_wraps_non_token_arguments_into_ExactValueToken($object)
  11. {
  12. $this->beConstructedWith(array(42, 'zet', $object));
  13. $class = get_class($object->getWrappedObject());
  14. $hash = spl_object_hash($object->getWrappedObject());
  15. $this->__toString()->shouldReturn("exact(42), exact(\"zet\"), exact($class:$hash Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n))");
  16. }
  17. /**
  18. * @param \Prophecy\Argument\Token\TokenInterface $token1
  19. * @param \Prophecy\Argument\Token\TokenInterface $token2
  20. * @param \Prophecy\Argument\Token\TokenInterface $token3
  21. */
  22. function it_generates_string_representation_from_all_tokens_imploded($token1, $token2, $token3)
  23. {
  24. $token1->__toString()->willReturn('token_1');
  25. $token2->__toString()->willReturn('token_2');
  26. $token3->__toString()->willReturn('token_3');
  27. $this->beConstructedWith(array($token1, $token2, $token3));
  28. $this->__toString()->shouldReturn('token_1, token_2, token_3');
  29. }
  30. /**
  31. * @param \Prophecy\Argument\Token\TokenInterface $token
  32. */
  33. function it_exposes_list_of_tokens($token)
  34. {
  35. $this->beConstructedWith(array($token));
  36. $this->getTokens()->shouldReturn(array($token));
  37. }
  38. function it_returns_score_of_1_if_there_are_no_tokens_and_arguments()
  39. {
  40. $this->beConstructedWith(array());
  41. $this->scoreArguments(array())->shouldReturn(1);
  42. }
  43. /**
  44. * @param \Prophecy\Argument\Token\TokenInterface $token1
  45. * @param \Prophecy\Argument\Token\TokenInterface $token2
  46. * @param \Prophecy\Argument\Token\TokenInterface $token3
  47. */
  48. function it_should_return_match_score_based_on_all_tokens_score($token1, $token2, $token3)
  49. {
  50. $token1->scoreArgument('one')->willReturn(3);
  51. $token1->isLast()->willReturn(false);
  52. $token2->scoreArgument(2)->willReturn(5);
  53. $token2->isLast()->willReturn(false);
  54. $token3->scoreArgument($obj = new \stdClass())->willReturn(10);
  55. $token3->isLast()->willReturn(false);
  56. $this->beConstructedWith(array($token1, $token2, $token3));
  57. $this->scoreArguments(array('one', 2, $obj))->shouldReturn(18);
  58. }
  59. /**
  60. * @param \Prophecy\Argument\Token\TokenInterface $token1
  61. * @param \Prophecy\Argument\Token\TokenInterface $token2
  62. * @param \Prophecy\Argument\Token\TokenInterface $token3
  63. */
  64. function it_returns_false_if_there_is_less_arguments_than_tokens($token1, $token2, $token3)
  65. {
  66. $token1->scoreArgument('one')->willReturn(3);
  67. $token1->isLast()->willReturn(false);
  68. $token2->scoreArgument(2)->willReturn(5);
  69. $token2->isLast()->willReturn(false);
  70. $token3->scoreArgument(null)->willReturn(false);
  71. $token3->isLast()->willReturn(false);
  72. $this->beConstructedWith(array($token1, $token2, $token3));
  73. $this->scoreArguments(array('one', 2))->shouldReturn(false);
  74. }
  75. /**
  76. * @param \Prophecy\Argument\Token\TokenInterface $token1
  77. * @param \Prophecy\Argument\Token\TokenInterface $token2
  78. * @param \Prophecy\Argument\Token\TokenInterface $token3
  79. */
  80. function it_returns_false_if_there_is_less_tokens_than_arguments($token1, $token2, $token3)
  81. {
  82. $token1->scoreArgument('one')->willReturn(3);
  83. $token1->isLast()->willReturn(false);
  84. $token2->scoreArgument(2)->willReturn(5);
  85. $token2->isLast()->willReturn(false);
  86. $token3->scoreArgument($obj = new \stdClass())->willReturn(10);
  87. $token3->isLast()->willReturn(false);
  88. $this->beConstructedWith(array($token1, $token2, $token3));
  89. $this->scoreArguments(array('one', 2, $obj, 4))->shouldReturn(false);
  90. }
  91. /**
  92. * @param \Prophecy\Argument\Token\TokenInterface $token1
  93. * @param \Prophecy\Argument\Token\TokenInterface $token2
  94. * @param \Prophecy\Argument\Token\TokenInterface $token3
  95. */
  96. function it_should_return_false_if_one_of_the_tokens_returns_false($token1, $token2, $token3)
  97. {
  98. $token1->scoreArgument('one')->willReturn(3);
  99. $token1->isLast()->willReturn(false);
  100. $token2->scoreArgument(2)->willReturn(false);
  101. $token2->isLast()->willReturn(false);
  102. $token3->scoreArgument($obj = new \stdClass())->willReturn(10);
  103. $token3->isLast()->willReturn(false);
  104. $this->beConstructedWith(array($token1, $token2, $token3));
  105. $this->scoreArguments(array('one', 2, $obj))->shouldReturn(false);
  106. }
  107. /**
  108. * @param \Prophecy\Argument\Token\TokenInterface $token1
  109. * @param \Prophecy\Argument\Token\TokenInterface $token2
  110. * @param \Prophecy\Argument\Token\TokenInterface $token3
  111. */
  112. function it_should_calculate_score_until_last_token($token1, $token2, $token3)
  113. {
  114. $token1->scoreArgument('one')->willReturn(3);
  115. $token1->isLast()->willReturn(false);
  116. $token2->scoreArgument(2)->willReturn(7);
  117. $token2->isLast()->willReturn(true);
  118. $token3->scoreArgument($obj = new \stdClass())->willReturn(10);
  119. $token3->isLast()->willReturn(false);
  120. $this->beConstructedWith(array($token1, $token2, $token3));
  121. $this->scoreArguments(array('one', 2, $obj))->shouldReturn(10);
  122. }
  123. }