No Description

ArgumentsWildcardSpec.php 5.1KB

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