Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Mocks / ConnectionMock.php
1 <?php
2
3 namespace Doctrine\Tests\Mocks;
4
5 class ConnectionMock extends \Doctrine\DBAL\Connection
6 {
7     private $_fetchOneResult;
8     private $_platformMock;
9     private $_lastInsertId = 0;
10     private $_inserts = array();
11     private $_executeUpdates = array();
12
13     public function __construct(array $params, $driver, $config = null, $eventManager = null)
14     {
15         $this->_platformMock = new DatabasePlatformMock();
16
17         parent::__construct($params, $driver, $config, $eventManager);
18
19         // Override possible assignment of platform to database platform mock
20         $this->_platform = $this->_platformMock;
21     }
22
23     /**
24      * @override
25      */
26     public function getDatabasePlatform()
27     {
28         return $this->_platformMock;
29     }
30
31     /**
32      * @override
33      */
34     public function insert($tableName, array $data, array $types = array())
35     {
36         $this->_inserts[$tableName][] = $data;
37     }
38
39     /**
40      * @override
41      */
42     public function executeUpdate($query, array $params = array(), array $types = array())
43     {
44         $this->_executeUpdates[] = array('query' => $query, 'params' => $params, 'types' => $types);
45     }
46
47     /**
48      * @override
49      */
50     public function lastInsertId($seqName = null)
51     {
52         return $this->_lastInsertId;
53     }
54
55     /**
56      * @override
57      */
58     public function fetchColumn($statement, array $params = array(), $colnum = 0)
59     {
60         return $this->_fetchOneResult;
61     }
62
63     /**
64      * @override
65      */
66     public function quote($input, $type = null)
67     {
68         if (is_string($input)) {
69             return "'" . $input . "'";
70         }
71         return $input;
72     }
73
74     /* Mock API */
75
76     public function setFetchOneResult($fetchOneResult)
77     {
78         $this->_fetchOneResult = $fetchOneResult;
79     }
80
81     public function setDatabasePlatform($platform)
82     {
83         $this->_platformMock = $platform;
84     }
85
86     public function setLastInsertId($id)
87     {
88         $this->_lastInsertId = $id;
89     }
90
91     public function getInserts()
92     {
93         return $this->_inserts;
94     }
95
96     public function getExecuteUpdates()
97     {
98         return $this->_executeUpdates;
99     }
100
101     public function reset()
102     {
103         $this->_inserts = array();
104         $this->_lastInsertId = 0;
105     }
106 }