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

StatementIteratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGettingIteratorDoesNotCallFetch() 0 10 1
A testIterationCallsFetchOncePerStep() 0 19 2
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