Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / 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
12     public function __construct(array $params, $driver, $config = null, $eventManager = null)
13     {
14         $this->_platformMock = new DatabasePlatformMock();
15
16         parent::__construct($params, $driver, $config, $eventManager);
17
18         // Override possible assignment of platform to database platform mock
19         $this->_platform = $this->_platformMock;
20     }
21
22     /**
23      * @override
24      */
25     public function getDatabasePlatform()
26     {
27         return $this->_platformMock;
28     }
29
30     /**
31      * @override
32      */
33     public function insert($tableName, array $data, array $types = array())
34     {
35         $this->_inserts[$tableName][] = $data;
36     }
37
38     /**
39      * @override
40      */
41     public function lastInsertId($seqName = null)
42     {
43         return $this->_lastInsertId;
44     }
45
46     /**
47      * @override
48      */
49     public function fetchColumn($statement, array $params = array(), $colnum = 0)
50     {
51         return $this->_fetchOneResult;
52     }
53
54     /**
55      * @override
56      */
57     public function quote($input, $type = null)
58     {
59         if (is_string($input)) {
60             return "'" . $input . "'";
61         }
62         return $input;
63     }
64
65     /* Mock API */
66
67     public function setFetchOneResult($fetchOneResult)
68     {
69         $this->_fetchOneResult = $fetchOneResult;
70     }
71
72     public function setDatabasePlatform($platform)
73     {
74         $this->_platformMock = $platform;
75     }
76
77     public function setLastInsertId($id)
78     {
79         $this->_lastInsertId = $id;
80     }
81
82     public function getInserts()
83     {
84         return $this->_inserts;
85     }
86
87     public function reset()
88     {
89         $this->_inserts = array();
90         $this->_lastInsertId = 0;
91     }
92 }