Completed
Push — master ( 373ae9...a0cc58 )
by Marco
13s
created

testIterationCallsFetchOncePerStep()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
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
        $stmt->expects($this->never())->method('fetchAll');
15
        $stmt->expects($this->never())->method('fetchColumn');
16
17
        $stmtIterator = new StatementIterator($stmt);
18
        $stmtIterator->getIterator();
19
    }
20
21
    public function testIterationCallsFetchOncePerStep()
22
    {
23
        $values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false, 'impossible'];
24
        $calls = 0;
25
26
        $stmt = $this->createMock(Statement::class);
27
        $stmt->expects($this->exactly(10))
28
            ->method('fetch')
29
            ->willReturnCallback(function() use ($values, &$calls) {
30
                $value = $values[$calls];
31
                $calls++;
32
                return $value;
33
            });
34
35
        $stmtIterator = new StatementIterator($stmt);
36
        foreach ($stmtIterator as $i => $_) {
37
            $this->assertEquals($i + 1, $calls);
38
        }
39
    }
40
}
41