ArrayEveryEntryTokenSpec.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace spec\Prophecy\Argument\Token;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument\Token\TokenInterface;
  5. class ArrayEveryEntryTokenSpec extends ObjectBehavior
  6. {
  7. function let(TokenInterface $value)
  8. {
  9. $this->beConstructedWith($value);
  10. }
  11. function it_implements_TokenInterface()
  12. {
  13. $this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
  14. }
  15. function it_is_not_last()
  16. {
  17. $this->shouldNotBeLast();
  18. }
  19. function it_holds_value($value)
  20. {
  21. $this->getValue()->shouldBe($value);
  22. }
  23. function its_string_representation_tells_that_its_an_array_containing_only_value($value)
  24. {
  25. $value->__toString()->willReturn('value');
  26. $this->__toString()->shouldBe('[value, ..., value]');
  27. }
  28. function it_wraps_non_token_value_into_ExactValueToken(\stdClass $stdClass)
  29. {
  30. $this->beConstructedWith($stdClass);
  31. $this->getValue()->shouldHaveType('Prophecy\Argument\Token\ExactValueToken');
  32. }
  33. function it_does_not_score_if_argument_is_neither_array_nor_traversable()
  34. {
  35. $this->scoreArgument('string')->shouldBe(false);
  36. $this->scoreArgument(new \stdClass)->shouldBe(false);
  37. }
  38. function it_does_not_score_empty_array()
  39. {
  40. $this->scoreArgument(array())->shouldBe(false);
  41. }
  42. function it_does_not_score_traversable_object_without_entries(\Iterator $object)
  43. {
  44. $object->rewind()->willReturn(null);
  45. $object->next()->willReturn(null);
  46. $object->valid()->willReturn(false);
  47. $this->scoreArgument($object)->shouldBe(false);
  48. }
  49. function it_scores_avg_of_scores_from_value_tokens($value)
  50. {
  51. $value->scoreArgument('value1')->willReturn(6);
  52. $value->scoreArgument('value2')->willReturn(3);
  53. $this->scoreArgument(array('value1', 'value2'))->shouldBe(4.5);
  54. }
  55. function it_scores_false_if_entry_scores_false($value)
  56. {
  57. $value->scoreArgument('value1')->willReturn(6);
  58. $value->scoreArgument('value2')->willReturn(false);
  59. $this->scoreArgument(array('value1', 'value2'))->shouldBe(false);
  60. }
  61. function it_does_not_score_array_keys($value)
  62. {
  63. $value->scoreArgument('value')->willReturn(6);
  64. $value->scoreArgument('key')->shouldNotBeCalled(0);
  65. $this->scoreArgument(array('key' => 'value'))->shouldBe(6);
  66. }
  67. function it_scores_traversable_object_from_value_token(TokenInterface $value, \Iterator $object)
  68. {
  69. $object->current()->will(function ($args, $object) {
  70. $object->valid()->willReturn(false);
  71. return 'value';
  72. });
  73. $object->key()->willReturn('key');
  74. $object->rewind()->willReturn(null);
  75. $object->next()->willReturn(null);
  76. $object->valid()->willReturn(true);
  77. $value->scoreArgument('value')->willReturn(2);
  78. $this->scoreArgument($object)->shouldBe(2);
  79. }
  80. }