Passed
Pull Request — master (#2718)
by Ian
14:13
created

testIterationCallsFetchOncePerStep()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 19
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 13
nc 2
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver;
4
5
use Doctrine\DBAL\Driver\Statement;
6
use Doctrine\DBAL\Driver\StatementIterator;
7
8
class StatementIteratorTest extends \Doctrine\Tests\DbalTestCase
9
{
10
    public function testGettingIteratorDoesNotCallFetch()
11
    {
12
        $stmt = $this->createMock(Statement::class);
13
        $stmt->expects($this->never())->method('fetch');
14
15
        $stmtIterator = new StatementIterator($stmt);
16
        $stmtIterator->getIterator();
17
    }
18
19
    public function testIterationCallsFetchOncePerStep()
20
    {
21
        $values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false];
22
        $calls = 0;
23
24
        $stmt = $this->createMock(Statement::class);
25
        $stmt->expects($this->exactly(10))
26
            ->method('fetch')
27
            ->willReturnCallback(function() use ($values, &$calls) {
28
                $value = $values[$calls];
29
                $calls++;
30
                return $value;
31
            });
32
33
        $stmtIterator = new StatementIterator($stmt);
34
        foreach ($stmtIterator as $i => $_) {
35
            $this->assertEquals($i + 1, $calls);
36
        }
37
    }
38
}
39