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
|
|
|
class EntityManagerBuilderTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @expectedException \InvalidArgumentException |
19
|
|
|
*/ |
20
|
|
|
public function testBadCacheDriver() |
21
|
|
|
{ |
22
|
|
|
$options = [ |
23
|
|
|
'cache_driver' => 'notValid', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
EntityManagerBuilder::build($options); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @expectedException \RuntimeException |
31
|
|
|
*/ |
32
|
|
|
public function testNoMetadata() |
33
|
|
|
{ |
34
|
|
|
$options = [ |
35
|
|
|
'annotation_files' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
36
|
|
|
'annotation_namespaces' => ['\Jgut\Slim\Doctrine'], |
37
|
|
|
'annotation_autoloaders' => [function () { |
38
|
|
|
}], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
EntityManagerBuilder::build($options); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @expectedException \InvalidArgumentException |
46
|
|
|
*/ |
47
|
|
|
public function testBadNamingStrategy() |
48
|
|
|
{ |
49
|
|
|
$options = [ |
50
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
51
|
|
|
'naming_strategy' => 'notValid', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
EntityManagerBuilder::build($options); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @expectedException \InvalidArgumentException |
59
|
|
|
*/ |
60
|
|
|
public function testBadQuoteStrategy() |
61
|
|
|
{ |
62
|
|
|
$options = [ |
63
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
64
|
|
|
'quote_strategy' => 'notValid', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
EntityManagerBuilder::build($options); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @expectedException \InvalidArgumentException |
72
|
|
|
*/ |
73
|
|
|
public function testNoCreation() |
74
|
|
|
{ |
75
|
|
|
$options = [ |
76
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
77
|
|
|
'proxies_namespace' => 'myNamespace\Proxies', |
78
|
|
|
'auto_generate_proxies' => AbstractProxyFactory::AUTOGENERATE_ALWAYS, |
79
|
|
|
'sql_logger' => new \Doctrine\DBAL\Logging\EchoSQLLogger, |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
EntityManagerBuilder::build($options); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testCreationFromAnnotationFile() |
86
|
|
|
{ |
87
|
|
|
$options = [ |
88
|
|
|
'connection' => [ |
89
|
|
|
'driver' => 'pdo_sqlite', |
90
|
|
|
'memory' => true, |
91
|
|
|
], |
92
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testCreationFromXMLFile() |
99
|
|
|
{ |
100
|
|
|
$options = [ |
101
|
|
|
'connection' => [ |
102
|
|
|
'driver' => 'pdo_sqlite', |
103
|
|
|
'memory' => true, |
104
|
|
|
], |
105
|
|
|
'xml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testCreationFromYAMLFile() |
112
|
|
|
{ |
113
|
|
|
$options = [ |
114
|
|
|
'connection' => [ |
115
|
|
|
'driver' => 'pdo_sqlite', |
116
|
|
|
'memory' => true, |
117
|
|
|
], |
118
|
|
|
'yaml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testCreationFromPHPFile() |
125
|
|
|
{ |
126
|
|
|
$options = [ |
127
|
|
|
'connection' => [ |
128
|
|
|
'driver' => 'pdo_sqlite', |
129
|
|
|
'memory' => true, |
130
|
|
|
], |
131
|
|
|
'php_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
132
|
|
|
]; |
133
|
|
|
|
134
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function testCustomType() |
138
|
|
|
{ |
139
|
|
|
$options = [ |
140
|
|
|
'connection' => [ |
141
|
|
|
'driver' => 'pdo_sqlite', |
142
|
|
|
'memory' => true, |
143
|
|
|
], |
144
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
145
|
|
|
'custom_types' => [ |
146
|
|
|
'custom' => '\Doctrine\DBAL\Types\DecimalType', |
147
|
|
|
], |
148
|
|
|
]; |
149
|
|
|
|
150
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @expectedException \RuntimeException |
155
|
|
|
*/ |
156
|
|
|
public function testDuplicatedType() |
157
|
|
|
{ |
158
|
|
|
$options = [ |
159
|
|
|
'connection' => [ |
160
|
|
|
'driver' => 'pdo_sqlite', |
161
|
|
|
'memory' => true, |
162
|
|
|
], |
163
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
164
|
|
|
'custom_types' => [ |
165
|
|
|
'integer' => '\Doctrine\DBAL\Types\DecimalType', |
166
|
|
|
], |
167
|
|
|
]; |
168
|
|
|
|
169
|
|
|
self::assertInstanceOf('\Doctrine\ORM\EntityManager', EntityManagerBuilder::build($options)); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|