Total Complexity | 4 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | class IterableFirstTest extends TestCase |
||
12 | { |
||
13 | use ProvideIterablesTrait; |
||
14 | |||
15 | public function provider() |
||
16 | { |
||
17 | return $this->provideIterables(['one', 'two', 'three'], true); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @dataProvider provider |
||
22 | */ |
||
23 | public function test($values) |
||
24 | { |
||
25 | $result = iterable_first($values); |
||
26 | |||
27 | $this->assertEquals('one', $result); |
||
28 | } |
||
29 | |||
30 | public function testNoWalk() |
||
31 | { |
||
32 | $iterator = $this->createMock(\Iterator::class); |
||
33 | $iterator->expects($this->any())->method('valid')->willReturn(true); |
||
34 | $iterator->expects($this->once())->method('current')->willReturn('one'); |
||
35 | |||
36 | $result = iterable_first($iterator); |
||
37 | |||
38 | $this->assertEquals('one', $result); |
||
39 | } |
||
40 | |||
41 | |||
42 | public function testEmpty() |
||
43 | { |
||
44 | $result = iterable_first(new \EmptyIterator()); |
||
45 | |||
46 | $this->assertNull($result); |
||
47 | } |
||
49 |