1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Slim3 Doctrine integration (https://github.com/juliangut/slim-doctrine) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/juliangut/slim-doctrine for the canonical source repository |
6
|
|
|
* |
7
|
|
|
* @license https://raw.githubusercontent.com/juliangut/slim-doctrine/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Jgut\Slim\Doctrine\Tests; |
11
|
|
|
|
12
|
|
|
use Jgut\Slim\Doctrine\EntityManagerBuilder; |
13
|
|
|
use Doctrine\Common\Proxy\AbstractProxyFactory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers Jgut\Slim\Doctrine\EntityManagerBuilder |
17
|
|
|
*/ |
18
|
|
|
class EntityManagerBuilderTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
22
|
|
|
* |
23
|
|
|
* @expectedException \InvalidArgumentException |
24
|
|
|
*/ |
25
|
|
|
public function testBadCacheDriver() |
26
|
|
|
{ |
27
|
|
|
$options = [ |
28
|
|
|
'cache_driver' => 'notValid', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
EntityManagerBuilder::build($options); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
36
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::setupAnnotationMetadata |
37
|
|
|
* |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
|
public function testNoMetadata() |
41
|
|
|
{ |
42
|
|
|
$options = [ |
43
|
|
|
'annotation_files' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
44
|
|
|
'annotation_namespaces' => ['\Jgut\Slim\Doctrine'], |
45
|
|
|
'annotation_autoloaders' => [function () { |
46
|
|
|
}], |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
EntityManagerBuilder::build($options); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
54
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
55
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::normalizePaths |
56
|
|
|
* |
57
|
|
|
* @expectedException \InvalidArgumentException |
58
|
|
|
*/ |
59
|
|
|
public function testBadNamingStrategy() |
60
|
|
|
{ |
61
|
|
|
$options = [ |
62
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
63
|
|
|
'naming_strategy' => 'notValid', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
EntityManagerBuilder::build($options); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
71
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
72
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::normalizePaths |
73
|
|
|
* |
74
|
|
|
* @expectedException \InvalidArgumentException |
75
|
|
|
*/ |
76
|
|
|
public function testBadQuoteStrategy() |
77
|
|
|
{ |
78
|
|
|
$options = [ |
79
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
80
|
|
|
'quote_strategy' => 'notValid', |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
EntityManagerBuilder::build($options); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
88
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::setupProxy |
89
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::setupSQLLogger |
90
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::setupCustomDQLFunctions |
91
|
|
|
* |
92
|
|
|
* @expectedException \InvalidArgumentException |
93
|
|
|
*/ |
94
|
|
|
public function testNoCreation() |
95
|
|
|
{ |
96
|
|
|
$options = [ |
97
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
98
|
|
|
'proxies_namespace' => 'myNamespace\Proxies', |
99
|
|
|
'auto_generate_proxies' => AbstractProxyFactory::AUTOGENERATE_ALWAYS, |
100
|
|
|
'sql_logger' => new \Doctrine\DBAL\Logging\EchoSQLLogger, |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
EntityManagerBuilder::build($options); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
108
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
109
|
|
|
*/ |
110
|
|
|
public function testCreationFromAnnotationFile() |
111
|
|
|
{ |
112
|
|
|
$options = [ |
113
|
|
|
'connection' => [ |
114
|
|
|
'driver' => 'pdo_sqlite', |
115
|
|
|
'memory' => true, |
116
|
|
|
], |
117
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
125
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
126
|
|
|
*/ |
127
|
|
|
public function testCreationFromXMLFile() |
128
|
|
|
{ |
129
|
|
|
$options = [ |
130
|
|
|
'connection' => [ |
131
|
|
|
'driver' => 'pdo_sqlite', |
132
|
|
|
'memory' => true, |
133
|
|
|
], |
134
|
|
|
'xml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
135
|
|
|
]; |
136
|
|
|
|
137
|
|
|
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
142
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
143
|
|
|
*/ |
144
|
|
|
public function testCreationFromYAMLFile() |
145
|
|
|
{ |
146
|
|
|
$options = [ |
147
|
|
|
'connection' => [ |
148
|
|
|
'driver' => 'pdo_sqlite', |
149
|
|
|
'memory' => true, |
150
|
|
|
], |
151
|
|
|
'yaml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
152
|
|
|
]; |
153
|
|
|
|
154
|
|
|
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
159
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
160
|
|
|
*/ |
161
|
|
|
public function testCreationFromPHPFile() |
162
|
|
|
{ |
163
|
|
|
$options = [ |
164
|
|
|
'connection' => [ |
165
|
|
|
'driver' => 'pdo_sqlite', |
166
|
|
|
'memory' => true, |
167
|
|
|
], |
168
|
|
|
'php_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
169
|
|
|
]; |
170
|
|
|
|
171
|
|
|
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::build |
176
|
|
|
* @cover \Jgut\Slim\Doctrine\EntityManagerBuilder::createConfiguration |
177
|
|
|
*/ |
178
|
|
|
public function testCustomTypes() |
179
|
|
|
{ |
180
|
|
|
$options = [ |
181
|
|
|
'connection' => [ |
182
|
|
|
'driver' => 'pdo_sqlite', |
183
|
|
|
'memory' => true, |
184
|
|
|
], |
185
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
186
|
|
|
'custom_types' => [ |
187
|
|
|
'custom' => '\Doctrine\DBAL\Types\DecimalType', |
188
|
|
|
], |
189
|
|
|
]; |
190
|
|
|
|
191
|
|
|
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|