Completed
Push — master ( 1eba78...18908c )
by Sergei
62:05 queued 10s
created

StatementTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 114
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testRowCount() 0 9 1
A testCloseCursor() 0 6 1
A testBindValue() 0 11 1
A createStatement() 0 3 1
A testExecute() 0 12 1
A testColumnCount() 0 9 1
A testGetIterator() 0 7 1
A createConnection() 0 5 1
A testBindParam() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Tests\Portability;
6
7
use Doctrine\DBAL\Driver\Statement as DriverStatement;
8
use Doctrine\DBAL\ParameterType;
9
use Doctrine\DBAL\Portability\Connection;
10
use Doctrine\DBAL\Portability\Statement;
11
use PHPUnit\Framework\MockObject\MockObject;
12
use PHPUnit\Framework\TestCase;
13
use function iterator_to_array;
14
15
class StatementTest extends TestCase
16
{
17
    /** @var Connection|MockObject */
18
    protected $conn;
19
20
    /** @var Statement */
21
    protected $stmt;
22
23
    /** @var DriverStatement|MockObject */
24
    protected $wrappedStmt;
25
26
    protected function setUp() : void
27
    {
28
        $this->wrappedStmt = $this->createMock(DriverStatement::class);
29
        $this->conn        = $this->createConnection();
30
        $this->stmt        = $this->createStatement($this->wrappedStmt, $this->conn);
31
    }
32
33
    /**
34
     * @group DBAL-726
35
     */
36
    public function testBindParam() : void
37
    {
38
        $column   = 'mycolumn';
39
        $variable = 'myvalue';
40
        $type     = ParameterType::STRING;
41
        $length   = 666;
42
43
        $this->wrappedStmt->expects(self::once())
44
            ->method('bindParam')
45
            ->with($column, $variable, $type, $length);
46
47
        $this->stmt->bindParam($column, $variable, $type, $length);
48
    }
49
50
    public function testBindValue() : void
51
    {
52
        $param = 'myparam';
53
        $value = 'myvalue';
54
        $type  = ParameterType::STRING;
55
56
        $this->wrappedStmt->expects(self::once())
57
            ->method('bindValue')
58
            ->with($param, $value, $type);
59
60
        $this->stmt->bindValue($param, $value, $type);
61
    }
62
63
    public function testCloseCursor() : void
64
    {
65
        $this->wrappedStmt->expects(self::once())
66
            ->method('closeCursor');
67
68
        $this->stmt->closeCursor();
69
    }
70
71
    public function testColumnCount() : void
72
    {
73
        $columnCount = 666;
74
75
        $this->wrappedStmt->expects(self::once())
76
            ->method('columnCount')
77
            ->will(self::returnValue($columnCount));
78
79
        self::assertSame($columnCount, $this->stmt->columnCount());
80
    }
81
82
    public function testExecute() : void
83
    {
84
        $params = [
85
            'foo',
86
            'bar',
87
        ];
88
89
        $this->wrappedStmt->expects(self::once())
90
            ->method('execute')
91
            ->with($params);
92
93
        $this->stmt->execute($params);
94
    }
95
96
    public function testGetIterator() : void
97
    {
98
        $this->wrappedStmt->expects(self::exactly(3))
99
            ->method('fetch')
100
            ->willReturnOnConsecutiveCalls('foo', 'bar', false);
101
102
        self::assertSame(['foo', 'bar'], iterator_to_array($this->stmt->getIterator()));
103
    }
104
105
    public function testRowCount() : void
106
    {
107
        $rowCount = 666;
108
109
        $this->wrappedStmt->expects(self::once())
110
            ->method('rowCount')
111
            ->will(self::returnValue($rowCount));
112
113
        self::assertSame($rowCount, $this->stmt->rowCount());
114
    }
115
116
    /**
117
     * @return Connection|MockObject
118
     */
119
    protected function createConnection()
120
    {
121
        return $this->getMockBuilder(Connection::class)
122
            ->disableOriginalConstructor()
123
            ->getMock();
124
    }
125
126
    protected function createStatement(DriverStatement $wrappedStatement, Connection $connection) : Statement
127
    {
128
        return new Statement($wrappedStatement, $connection);
129
    }
130
}
131