Нет описания

ArrayEveryEntryTokenSpec.php 3.1KB

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