|
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 Doctrine\Common\EventManager; |
|
13
|
|
|
use Doctrine\MongoDB\Connection; |
|
14
|
|
|
use Jgut\Slim\Doctrine\DocumentManagerBuilder; |
|
15
|
|
|
use Doctrine\Common\Proxy\AbstractProxyFactory; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @covers Jgut\Slim\Doctrine\DocumentManagerBuilder |
|
19
|
|
|
*/ |
|
20
|
|
|
class DocumentManagerBuilderTest extends \PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @expectedException \InvalidArgumentException |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testBadCacheDriver() |
|
26
|
|
|
{ |
|
27
|
|
|
$options = [ |
|
28
|
|
|
'cache_driver' => 'notValid', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
DocumentManagerBuilder::build($options); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @expectedException \RuntimeException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testNoMetadata() |
|
38
|
|
|
{ |
|
39
|
|
|
$options = [ |
|
40
|
|
|
'annotation_files' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
|
41
|
|
|
'annotation_namespaces' => ['\Jgut\Slim\Doctrine'], |
|
42
|
|
|
'annotation_autoloaders' => [function () { |
|
43
|
|
|
}], |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
DocumentManagerBuilder::build($options); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @expectedException \InvalidArgumentException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testNoConnection() |
|
53
|
|
|
{ |
|
54
|
|
|
$options = [ |
|
55
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
|
56
|
|
|
'default_database' => 'test', |
|
57
|
|
|
'proxies_namespace' => 'myNamespace\Proxies', |
|
58
|
|
|
'auto_generate_proxies' => AbstractProxyFactory::AUTOGENERATE_ALWAYS, |
|
59
|
|
|
'hydrators_namespace' => 'myNamespace\Hydrators', |
|
60
|
|
|
'logger_callable' => function () { |
|
61
|
|
|
}, |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
DocumentManagerBuilder::build($options); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @expectedException \RuntimeException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function testBadEventManager() |
|
71
|
|
|
{ |
|
72
|
|
|
$options = [ |
|
73
|
|
|
'connection' => new Connection(), |
|
74
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
|
75
|
|
|
'default_database' => 'test', |
|
76
|
|
|
'proxies_namespace' => 'myNamespace\Proxies', |
|
77
|
|
|
'auto_generate_proxies' => AbstractProxyFactory::AUTOGENERATE_ALWAYS, |
|
78
|
|
|
'hydrators_namespace' => 'myNamespace\Hydrators', |
|
79
|
|
|
'logger_callable' => function () { |
|
80
|
|
|
}, |
|
81
|
|
|
'event_manager' => new EventManager() |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
DocumentManagerBuilder::build($options); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testCreationFromAnnotationFile() |
|
88
|
|
|
{ |
|
89
|
|
|
$options = [ |
|
90
|
|
|
'connection' => new Connection('mongodb://localhost:27017'), |
|
91
|
|
|
'annotation_paths' => sys_get_temp_dir(), |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
self::assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testCreationFromXMLFile() |
|
98
|
|
|
{ |
|
99
|
|
|
$options = [ |
|
100
|
|
|
'connection' => [ |
|
101
|
|
|
'server' => 'mongodb://localhost:27017', |
|
102
|
|
|
], |
|
103
|
|
|
'xml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
self::assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options)); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function testCreationFromYAMLFile() |
|
110
|
|
|
{ |
|
111
|
|
|
$options = [ |
|
112
|
|
|
'connection' => [ |
|
113
|
|
|
'server' => 'mongodb://localhost:27017', |
|
114
|
|
|
], |
|
115
|
|
|
'yaml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
|
116
|
|
|
]; |
|
117
|
|
|
|
|
118
|
|
|
self::assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options)); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testCreationFromPHPFile() |
|
122
|
|
|
{ |
|
123
|
|
|
$options = [ |
|
124
|
|
|
'connection' => [ |
|
125
|
|
|
'server' => 'mongodb://localhost:27017', |
|
126
|
|
|
], |
|
127
|
|
|
'php_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'], |
|
128
|
|
|
]; |
|
129
|
|
|
|
|
130
|
|
|
self::assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options)); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|