Failed Conditions
Branch master (01ba0d)
by Arnold
06:58 queued 01:45
created

IterableFirstTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4
1
<?php
2
3
namespace Jasny\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use function Jasny\iterable_first;
7
8
/**
9
 * @covers \Jasny\iterable_first
10
 */
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
    }
48
}
49