Drupal investigation

ArgumentsWildcardSpec.php 4.5KB

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