|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace DoctrineORMModuleTest\Service; |
|
21
|
|
|
|
|
22
|
|
|
use PHPUnit_Framework_TestCase; |
|
23
|
|
|
use DoctrineORMModuleTest\Assets\Types\MoneyType; |
|
24
|
|
|
use DoctrineORMModule\Service\DBALConnectionFactory; |
|
25
|
|
|
use Doctrine\DBAL\Types\Type; |
|
26
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
|
27
|
|
|
use Doctrine\Common\EventManager; |
|
28
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
29
|
|
|
use DoctrineORMModule\Service\ConfigurationFactory; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @covers \DoctrineORMModule\Service\DBALConnectionFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
class DBALConnectionFactoryTest extends PHPUnit_Framework_TestCase |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @var ServiceManager |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $serviceManager; |
|
40
|
|
|
/** |
|
41
|
|
|
* @var DBALConnectionFactory |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $factory; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setUp() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->serviceManager = new ServiceManager(); |
|
51
|
|
|
$this->factory = new DBALConnectionFactory('orm_default'); |
|
52
|
|
|
$this->serviceManager->setService('doctrine.cache.array', new ArrayCache()); |
|
53
|
|
|
$this->serviceManager->setService('doctrine.eventmanager.orm_default', new EventManager()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testDoctrineMappingTypeReturnCorrectParent() |
|
57
|
|
|
{ |
|
58
|
|
|
$config = array( |
|
59
|
|
|
'doctrine' => array( |
|
60
|
|
|
'connection' => array( |
|
61
|
|
|
'orm_default' => array( |
|
62
|
|
|
'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', |
|
63
|
|
|
'params' => array( |
|
64
|
|
|
'memory' => true, |
|
65
|
|
|
), |
|
66
|
|
|
'doctrineTypeMappings' => array( |
|
67
|
|
|
'money' => 'string' |
|
68
|
|
|
), |
|
69
|
|
|
) |
|
70
|
|
|
), |
|
71
|
|
|
), |
|
72
|
|
|
); |
|
73
|
|
|
$configurationMock = $this->getMockBuilder('Doctrine\ORM\Configuration') |
|
74
|
|
|
->disableOriginalConstructor() |
|
75
|
|
|
->getMock(); |
|
76
|
|
|
|
|
77
|
|
|
$this->serviceManager->setService('doctrine.configuration.orm_default', $configurationMock); |
|
78
|
|
|
$this->serviceManager->setService('Config', $config); |
|
79
|
|
|
$this->serviceManager->setService('Configuration', $config); |
|
80
|
|
|
|
|
81
|
|
|
$dbal = $this->factory->createService($this->serviceManager); |
|
82
|
|
|
$platform = $dbal->getDatabasePlatform(); |
|
83
|
|
|
$this->assertSame('string', $platform->getDoctrineTypeMapping("money")); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testDoctrineAddCustomCommentedType() |
|
87
|
|
|
{ |
|
88
|
|
|
$config = array( |
|
89
|
|
|
'doctrine' => array( |
|
90
|
|
|
'connection' => array( |
|
91
|
|
|
'orm_default' => array( |
|
92
|
|
|
'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', |
|
93
|
|
|
'params' => array( |
|
94
|
|
|
'memory' => true, |
|
95
|
|
|
), |
|
96
|
|
|
'doctrineTypeMappings' => array( |
|
97
|
|
|
'money' => 'money', |
|
98
|
|
|
), |
|
99
|
|
|
'doctrineCommentedTypes' => array( |
|
100
|
|
|
'money' |
|
101
|
|
|
), |
|
102
|
|
|
) |
|
103
|
|
|
), |
|
104
|
|
|
'configuration' => array( |
|
105
|
|
|
'orm_default' => array( |
|
106
|
|
|
'types' => array( |
|
107
|
|
|
'money' => 'DoctrineORMModuleTest\Assets\Types\MoneyType', |
|
108
|
|
|
), |
|
109
|
|
|
), |
|
110
|
|
|
), |
|
111
|
|
|
), |
|
112
|
|
|
); |
|
113
|
|
|
$this->serviceManager->setService('Config', $config); |
|
114
|
|
|
$this->serviceManager->setService('Configuration', $config); |
|
115
|
|
|
$this->serviceManager->setService( |
|
116
|
|
|
'doctrine.driver.orm_default', |
|
117
|
|
|
$this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver') |
|
118
|
|
|
); |
|
119
|
|
|
$configurationFactory = new ConfigurationFactory('orm_default'); |
|
120
|
|
|
$this->serviceManager->setService( |
|
121
|
|
|
'doctrine.configuration.orm_default', |
|
122
|
|
|
$configurationFactory->createService($this->serviceManager) |
|
123
|
|
|
); |
|
124
|
|
|
$dbal = $this->factory->createService($this->serviceManager); |
|
125
|
|
|
$platform = $dbal->getDatabasePlatform(); |
|
126
|
|
|
$type = Type::getType($platform->getDoctrineTypeMapping("money")); |
|
127
|
|
|
|
|
128
|
|
|
$this->assertInstanceOf('DoctrineORMModuleTest\Assets\Types\MoneyType', $type); |
|
129
|
|
|
$this->assertTrue($platform->isCommentedDoctrineType($type)); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|