Hoa central
Limit.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator\Test\Unit;
38 
39 use Hoa\Iterator as LUT;
40 use Hoa\Test;
41 
50 class Limit extends Test\Unit\Suite
51 {
52  private static $_dummyArray = ['f', 'o', 'o', 'b', 'a', 'r'];
53 
54 
55 
56  public function case_classic()
57  {
58  $this
59  ->given(
60  $iterator = new LUT\Map(self::$_dummyArray),
61  $limit = new LUT\Limit($iterator, 2, 3)
62  )
63  ->when($result = iterator_to_array($limit))
64  ->then
65  ->array($result)
66  ->isEqualTo([
67  2 => 'o',
68  3 => 'b',
69  4 => 'a'
70  ]);
71  }
72 
73  public function case_negative_offset()
74  {
75  $this
76  ->given($iterator = new LUT\Map(self::$_dummyArray))
77  ->exception(function () use ($iterator) {
78  new LUT\Limit($iterator, -2, 3);
79  })
80  ->isInstanceOf('OutOfRangeException');
81  }
82 
83  public function case_empty()
84  {
85  $this
86  ->given(
87  $iterator = new LUT\Map(self::$_dummyArray),
88  $limit = new LUT\Limit($iterator, 0, 0)
89  )
90  ->exception(function () use ($limit) {
91  iterator_to_array($limit);
92  })
93  ->isInstanceOf('OutOfBoundsException');
94  }
95 }