ConnectionMock.php 1.45 KB
Newer Older
1 2
<?php

3
namespace Doctrine\Tests\Mocks;
4
use function is_string;
romanb's avatar
romanb committed
5

6
class ConnectionMock extends \Doctrine\DBAL\Connection
7
{
Gabriel Caruso's avatar
Gabriel Caruso committed
8 9 10
    /**
     * @var DatabasePlatformMock
     */
11
    private $_platformMock;
Gabriel Caruso's avatar
Gabriel Caruso committed
12 13 14 15

    /**
     * @var int
     */
romanb's avatar
romanb committed
16
    private $_lastInsertId = 0;
Gabriel Caruso's avatar
Gabriel Caruso committed
17 18

    /**
19
     * @var string[][]
Gabriel Caruso's avatar
Gabriel Caruso committed
20
     */
romanb's avatar
romanb committed
21
    private $_inserts = array();
22

23 24
    public function __construct(array $params, $driver, $config = null, $eventManager = null)
    {
25
        $this->_platformMock = new DatabasePlatformMock();
26 27

        parent::__construct($params, $driver, $config, $eventManager);
28
    }
29

30 31 32
    /**
     * @override
     */
romanb's avatar
romanb committed
33
    public function getDatabasePlatform()
34
    {
romanb's avatar
romanb committed
35
        return $this->_platformMock;
36
    }
37

38 39 40
    /**
     * @override
     */
41
    public function insert($tableName, array $data, array $types = array())
42
    {
romanb's avatar
romanb committed
43
        $this->_inserts[$tableName][] = $data;
44
    }
45

romanb's avatar
romanb committed
46 47 48
    /**
     * @override
     */
romanb's avatar
romanb committed
49
    public function lastInsertId($seqName = null)
romanb's avatar
romanb committed
50
    {
romanb's avatar
romanb committed
51 52
        return $this->_lastInsertId;
    }
53

romanb's avatar
romanb committed
54 55 56 57 58
    /**
     * @override
     */
    public function quote($input, $type = null)
    {
romanb's avatar
romanb committed
59
        if (is_string($input)) {
romanb's avatar
romanb committed
60 61 62
            return "'" . $input . "'";
        }
        return $input;
romanb's avatar
romanb committed
63
    }
64

romanb's avatar
romanb committed
65
    public function setLastInsertId($id)
66
    {
romanb's avatar
romanb committed
67
        $this->_lastInsertId = $id;
68
    }
69

romanb's avatar
romanb committed
70 71 72 73
    public function getInserts()
    {
        return $this->_inserts;
    }
74

romanb's avatar
romanb committed
75 76 77
    public function reset()
    {
        $this->_inserts = array();
romanb's avatar
romanb committed
78
        $this->_lastInsertId = 0;
romanb's avatar
romanb committed
79
    }
Gabriel Caruso's avatar
Gabriel Caruso committed
80
}