19
19
20
20
namespace DoctrineORMModuleTest \Service ;
21
21
22
- use PHPUnit \Framework \TestCase ;
22
+ use Doctrine \Common \Persistence \Mapping \Driver \MappingDriver ;
23
+ use Doctrine \DBAL \Driver \PDOSqlite \Driver as PDOSqliteDriver ;
24
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
25
+ use Doctrine \ORM \Configuration ;
23
26
use DoctrineORMModuleTest \Assets \Types \MoneyType ;
27
+ use PHPUnit \Framework \TestCase ;
24
28
use DoctrineORMModule \Service \DBALConnectionFactory ;
25
29
use Doctrine \DBAL \Types \Type ;
26
30
use Doctrine \Common \Cache \ArrayCache ;
@@ -59,15 +63,15 @@ public function testNoConnectWithoutCustomMappingsAndCommentedTypes()
59
63
'doctrine ' => [
60
64
'connection ' => [
61
65
'orm_default ' => [
62
- 'driverClass ' => \ Doctrine \ DBAL \ Driver \ PDOSqlite \Driver ::class,
66
+ 'driverClass ' => PDOSqliteDriver ::class,
63
67
'params ' => [
64
68
'memory ' => true ,
65
69
],
66
70
]
67
71
],
68
72
],
69
73
];
70
- $ configurationMock = $ this ->getMockBuilder (\ Doctrine \ ORM \ Configuration::class)
74
+ $ configurationMock = $ this ->getMockBuilder (Configuration::class)
71
75
->disableOriginalConstructor ()
72
76
->getMock ();
73
77
@@ -85,7 +89,7 @@ public function testDoctrineMappingTypeReturnCorrectParent()
85
89
'doctrine ' => [
86
90
'connection ' => [
87
91
'orm_default ' => [
88
- 'driverClass ' => \ Doctrine \ DBAL \ Driver \ PDOSqlite \Driver ::class,
92
+ 'driverClass ' => PDOSqliteDriver ::class,
89
93
'params ' => [
90
94
'memory ' => true ,
91
95
],
@@ -96,7 +100,7 @@ public function testDoctrineMappingTypeReturnCorrectParent()
96
100
],
97
101
],
98
102
];
99
- $ configurationMock = $ this ->getMockBuilder (\ Doctrine \ ORM \ Configuration::class)
103
+ $ configurationMock = $ this ->getMockBuilder (Configuration::class)
100
104
->disableOriginalConstructor ()
101
105
->getMock ();
102
106
@@ -115,7 +119,7 @@ public function testDoctrineAddCustomCommentedType()
115
119
'doctrine ' => [
116
120
'connection ' => [
117
121
'orm_default ' => [
118
- 'driverClass ' => \ Doctrine \ DBAL \ Driver \ PDOSqlite \Driver ::class,
122
+ 'driverClass ' => PDOSqliteDriver ::class,
119
123
'params ' => [
120
124
'memory ' => true ,
121
125
],
@@ -130,7 +134,7 @@ public function testDoctrineAddCustomCommentedType()
130
134
'configuration ' => [
131
135
'orm_default ' => [
132
136
'types ' => [
133
- 'money ' => \ DoctrineORMModuleTest \ Assets \ Types \ MoneyType::class,
137
+ 'money ' => MoneyType::class,
134
138
],
135
139
],
136
140
],
@@ -140,7 +144,7 @@ public function testDoctrineAddCustomCommentedType()
140
144
$ this ->serviceManager ->setService ('Configuration ' , $ config );
141
145
$ this ->serviceManager ->setService (
142
146
'doctrine.driver.orm_default ' ,
143
- $ this ->createMock (\ Doctrine \ Common \ Persistence \ Mapping \ Driver \ MappingDriver::class)
147
+ $ this ->createMock (MappingDriver::class)
144
148
);
145
149
$ configurationFactory = new ConfigurationFactory ('orm_default ' );
146
150
$ this ->serviceManager ->setService (
@@ -151,7 +155,39 @@ public function testDoctrineAddCustomCommentedType()
151
155
$ platform = $ dbal ->getDatabasePlatform ();
152
156
$ type = Type::getType ($ platform ->getDoctrineTypeMapping ("money " ));
153
157
154
- $ this ->assertInstanceOf (\ DoctrineORMModuleTest \ Assets \ Types \ MoneyType::class, $ type );
158
+ $ this ->assertInstanceOf (MoneyType::class, $ type );
155
159
$ this ->assertTrue ($ platform ->isCommentedDoctrineType ($ type ));
156
160
}
161
+
162
+ public function testGettingPlatformFromContainer ()
163
+ {
164
+ $ config = [
165
+ 'doctrine ' => [
166
+ 'connection ' => [
167
+ 'orm_default ' => [
168
+ 'driverClass ' => PDOSqliteDriver::class,
169
+ 'params ' => [
170
+ 'platform ' => 'platform_service ' ,
171
+ ],
172
+ ]
173
+ ],
174
+ ],
175
+ ];
176
+ $ configurationMock = $ this ->getMockBuilder (Configuration::class)
177
+ ->disableOriginalConstructor ()
178
+ ->getMock ();
179
+
180
+ $ platformMock = $ this ->getMockBuilder (AbstractPlatform::class)
181
+ ->disableOriginalConstructor ()
182
+ ->getMock ();
183
+
184
+ $ this ->serviceManager ->setService ('doctrine.configuration.orm_default ' , $ configurationMock );
185
+ $ this ->serviceManager ->setService ('config ' , $ config );
186
+ $ this ->serviceManager ->setService ('Configuration ' , $ config );
187
+ $ this ->serviceManager ->setService ('platform_service ' , $ platformMock );
188
+
189
+ $ dbal = $ this ->factory ->createService ($ this ->serviceManager );
190
+ $ platform = $ dbal ->getDatabasePlatform ();
191
+ $ this ->assertSame ($ platformMock , $ platform );
192
+ }
157
193
}
0 commit comments