LogicalAndTokenSpec.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace spec\Prophecy\Argument\Token;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use Prophecy\Argument\Token\TokenInterface;
  6. class LogicalAndTokenSpec extends ObjectBehavior
  7. {
  8. function it_implements_TokenInterface()
  9. {
  10. $this->beConstructedWith(array());
  11. $this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
  12. }
  13. function it_is_not_last()
  14. {
  15. $this->beConstructedWith(array());
  16. $this->shouldNotBeLast();
  17. }
  18. function it_generates_string_representation_from_all_tokens_imploded(
  19. TokenInterface $token1,
  20. TokenInterface $token2,
  21. TokenInterface $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('bool(token_1 AND token_2 AND token_3)');
  28. }
  29. function it_wraps_non_token_arguments_into_ExactValueToken()
  30. {
  31. $this->beConstructedWith(array(15, '1985'));
  32. $this->__toString()->shouldReturn("bool(exact(15) AND exact(\"1985\"))");
  33. }
  34. function it_scores_the_maximum_score_from_all_scores_returned_by_tokens(TokenInterface $token1, TokenInterface $token2)
  35. {
  36. $token1->scoreArgument(1)->willReturn(10);
  37. $token2->scoreArgument(1)->willReturn(5);
  38. $this->beConstructedWith(array($token1, $token2));
  39. $this->scoreArgument(1)->shouldReturn(10);
  40. }
  41. function it_does_not_score_if_there_are_no_arguments_or_tokens()
  42. {
  43. $this->beConstructedWith(array());
  44. $this->scoreArgument('any')->shouldReturn(false);
  45. }
  46. function it_does_not_score_if_either_of_tokens_does_not_score(TokenInterface $token1, TokenInterface $token2)
  47. {
  48. $token1->scoreArgument(1)->willReturn(10);
  49. $token1->scoreArgument(2)->willReturn(false);
  50. $token2->scoreArgument(1)->willReturn(false);
  51. $token2->scoreArgument(2)->willReturn(10);
  52. $this->beConstructedWith(array($token1, $token2));
  53. $this->scoreArgument(1)->shouldReturn(false);
  54. $this->scoreArgument(2)->shouldReturn(false);
  55. }
  56. }