Passed
Pull Request — master (#3002)
by Gabriel
14:52 queued 05:15
created

ConnectionMock::lastInsertId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\Tests\Mocks;
4
5
class ConnectionMock extends \Doctrine\DBAL\Connection
6
{
7
    /**
8
     * @var DatabasePlatformMock
9
     */
10
    private $_platformMock;
11
12
    /**
13
     * @var int
14
     */
15
    private $_lastInsertId = 0;
16
17
    /**
18
     * @var string[][]
19
     */
20
    private $_inserts = array();
21
22
    public function __construct(array $params, $driver, $config = null, $eventManager = null)
23
    {
24
        $this->_platformMock = new DatabasePlatformMock();
25
26
        parent::__construct($params, $driver, $config, $eventManager);
27
28
        // Override possible assignment of platform to database platform mock
29
        $this->_platform = $this->_platformMock;
0 ignored issues
show
Bug Best Practice introduced by
The property _platform does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
    }
31
32
    /**
33
     * @override
34
     */
35
    public function getDatabasePlatform()
36
    {
37
        return $this->_platformMock;
38
    }
39
40
    /**
41
     * @override
42
     */
43
    public function insert($tableName, array $data, array $types = array())
44
    {
45
        $this->_inserts[$tableName][] = $data;
46
    }
47
48
    /**
49
     * @override
50
     */
51
    public function lastInsertId($seqName = null)
52
    {
53
        return $this->_lastInsertId;
54
    }
55
56
    /**
57
     * @override
58
     */
59
    public function quote($input, $type = null)
60
    {
61
        if (is_string($input)) {
62
            return "'" . $input . "'";
63
        }
64
        return $input;
65
    }
66
67
    public function setLastInsertId($id)
68
    {
69
        $this->_lastInsertId = $id;
70
    }
71
72
    public function getInserts()
73
    {
74
        return $this->_inserts;
75
    }
76
77
    public function reset()
78
    {
79
        $this->_inserts = array();
80
        $this->_lastInsertId = 0;
81
    }
82
}
83