| Total Complexity | 8 |
| Total Lines | 85 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class IteratorSpec extends ObjectBehavior |
||
| 13 | { |
||
| 14 | use DictionaryBehavior; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var bool |
||
| 18 | */ |
||
| 19 | private $executed; |
||
| 20 | |||
| 21 | function let() |
||
| 22 | { |
||
| 23 | $this->executed = false; |
||
| 24 | |||
| 25 | $this->beConstructedWith('foo', $this->execution()); |
||
| 26 | } |
||
| 27 | |||
| 28 | function it_is_initializable() |
||
|
|
|||
| 29 | { |
||
| 30 | $this->shouldHaveType(Iterator::class); |
||
| 31 | } |
||
| 32 | |||
| 33 | function it_supports_some_array_access_functions() |
||
| 34 | { |
||
| 35 | $dictionary = $this->getWrappedObject(); |
||
| 36 | |||
| 37 | $this['foo']->shouldBe(0); |
||
| 38 | $this->shouldHaveKey('foo'); |
||
| 39 | |||
| 40 | $this['foo'] = 'test'; |
||
| 41 | $this['foo']->shouldBe('test'); |
||
| 42 | |||
| 43 | unset($dictionary['foo']); |
||
| 44 | $this->shouldNotHaveKey('foo'); |
||
| 45 | } |
||
| 46 | |||
| 47 | function it_is_hydrated_just_once() |
||
| 48 | { |
||
| 49 | Assert::false($this->executed); |
||
| 50 | |||
| 51 | $this->shouldYieldLike([ |
||
| 52 | 'foo' => 0, |
||
| 53 | 'bar' => 1, |
||
| 54 | 'baz' => 2, |
||
| 55 | ]); |
||
| 56 | |||
| 57 | Assert::true($this->executed); |
||
| 58 | |||
| 59 | $this->shouldYieldLike([ |
||
| 60 | 'foo' => 0, |
||
| 61 | 'bar' => 1, |
||
| 62 | 'baz' => 2, |
||
| 63 | ]); |
||
| 64 | |||
| 65 | Assert::true($this->executed); |
||
| 66 | } |
||
| 67 | |||
| 68 | protected function getExpectedResult(): array |
||
| 69 | { |
||
| 70 | return [ |
||
| 71 | 'foo' => 0, |
||
| 72 | 'bar' => 1, |
||
| 73 | 'baz' => 2, |
||
| 74 | ]; |
||
| 75 | } |
||
| 76 | |||
| 77 | protected function getExpectedName(): string |
||
| 78 | { |
||
| 79 | return 'foo'; |
||
| 80 | } |
||
| 81 | |||
| 82 | private function execution(): iterable |
||
| 97 | } |
||
| 98 | } |
||
| 99 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.