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

StatementIteratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGettingIteratorDoesNotCallFetch() 0 8 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
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