1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Tools; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
6
|
|
|
use Doctrine\Common\Cache\Cache; |
7
|
|
|
use Doctrine\ORM\Configuration; |
8
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
9
|
|
|
use Doctrine\ORM\Mapping\Driver\XmlDriver; |
10
|
|
|
use Doctrine\ORM\Mapping\Driver\YamlDriver; |
11
|
|
|
use Doctrine\ORM\Tools\Setup; |
12
|
|
|
use Doctrine\ORM\Version; |
13
|
|
|
use Doctrine\Tests\OrmTestCase; |
14
|
|
|
|
15
|
|
|
class SetupTest extends OrmTestCase |
16
|
|
|
{ |
17
|
|
|
private $originalAutoloaderCount; |
18
|
|
|
private $originalIncludePath; |
19
|
|
|
|
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
if (strpos(Version::VERSION, "DEV") === false) { |
23
|
|
|
$this->markTestSkipped("Test only runs in a dev-installation from Github"); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$this->originalAutoloaderCount = count(spl_autoload_functions()); |
27
|
|
|
$this->originalIncludePath = get_include_path(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function tearDown() |
31
|
|
|
{ |
32
|
|
|
if ( ! $this->originalIncludePath) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
set_include_path($this->originalIncludePath); |
37
|
|
|
$loaders = spl_autoload_functions(); |
38
|
|
|
$numberOfLoaders = count($loaders); |
39
|
|
|
for ($i = 0; $i < $numberOfLoaders; $i++) { |
40
|
|
|
if ($i > $this->originalAutoloaderCount+1) { |
41
|
|
|
spl_autoload_unregister($loaders[$i]); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDirectoryAutoload() |
47
|
|
|
{ |
48
|
|
|
Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../vendor/doctrine/common/lib"); |
49
|
|
|
|
50
|
|
|
$this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testAnnotationConfiguration() |
54
|
|
|
{ |
55
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true); |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf(Configuration::class, $config); |
58
|
|
|
$this->assertEquals(sys_get_temp_dir(), $config->getProxyDir()); |
59
|
|
|
$this->assertEquals('DoctrineProxies', $config->getProxyNamespace()); |
60
|
|
|
$this->assertInstanceOf(AnnotationDriver::class, $config->getMetadataDriverImpl()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testXMLConfiguration() |
64
|
|
|
{ |
65
|
|
|
$config = Setup::createXMLMetadataConfiguration([], true); |
66
|
|
|
|
67
|
|
|
$this->assertInstanceOf(Configuration::class, $config); |
68
|
|
|
$this->assertInstanceOf(XmlDriver::class, $config->getMetadataDriverImpl()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testYAMLConfiguration() |
72
|
|
|
{ |
73
|
|
|
$config = Setup::createYAMLMetadataConfiguration([], true); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf(Configuration::class, $config); |
76
|
|
|
$this->assertInstanceOf(YamlDriver::class, $config->getMetadataDriverImpl()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @group 5904 |
81
|
|
|
*/ |
82
|
|
|
public function testCacheNamespaceShouldBeGeneratedWhenCacheIsNotGiven() : void |
83
|
|
|
{ |
84
|
|
|
$config = Setup::createConfiguration(false, '/foo'); |
85
|
|
|
$cache = $config->getMetadataCacheImpl(); |
86
|
|
|
|
87
|
|
|
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @group 5904 |
92
|
|
|
*/ |
93
|
|
|
public function testCacheNamespaceShouldBeGeneratedWhenCacheIsGivenButHasNoNamespace() : void |
94
|
|
|
{ |
95
|
|
|
$config = Setup::createConfiguration(false, '/foo', new ArrayCache()); |
96
|
|
|
$cache = $config->getMetadataCacheImpl(); |
97
|
|
|
|
98
|
|
|
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @group 5904 |
103
|
|
|
*/ |
104
|
|
|
public function testConfiguredCacheNamespaceShouldBeUsedAsPrefixOfGeneratedNamespace() : void |
105
|
|
|
{ |
106
|
|
|
$originalCache = new ArrayCache(); |
107
|
|
|
$originalCache->setNamespace('foo'); |
108
|
|
|
|
109
|
|
|
$config = Setup::createConfiguration(false, '/foo', $originalCache); |
110
|
|
|
$cache = $config->getMetadataCacheImpl(); |
111
|
|
|
|
112
|
|
|
self::assertSame($originalCache, $cache); |
113
|
|
|
self::assertSame('foo:dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @group DDC-1350 |
118
|
|
|
*/ |
119
|
|
|
public function testConfigureProxyDir() |
120
|
|
|
{ |
121
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true, "/foo"); |
122
|
|
|
$this->assertEquals('/foo', $config->getProxyDir()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @group DDC-1350 |
127
|
|
|
*/ |
128
|
|
|
public function testConfigureCache() |
129
|
|
|
{ |
130
|
|
|
$cache = new ArrayCache(); |
131
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], false, null, $cache); |
132
|
|
|
|
133
|
|
|
$this->assertSame($cache, $config->getResultCacheImpl()); |
134
|
|
|
$this->assertSame($cache, $config->getMetadataCacheImpl()); |
135
|
|
|
$this->assertSame($cache, $config->getQueryCacheImpl()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testDevModeOverridesCacheCustomInstance() |
139
|
|
|
{ |
140
|
|
|
$cache = new ArrayCache(); |
141
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true, null, $cache); |
142
|
|
|
|
143
|
|
|
$this->assertNotSame($cache, $config->getResultCacheImpl()); |
144
|
|
|
$this->assertNotSame($cache, $config->getMetadataCacheImpl()); |
145
|
|
|
$this->assertNotSame($cache, $config->getQueryCacheImpl()); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @group DDC-3190 |
150
|
|
|
*/ |
151
|
|
|
public function testConfigureCacheCustomInstance() |
152
|
|
|
{ |
153
|
|
|
$cache = $this->createMock(Cache::class); |
154
|
|
|
$config = Setup::createConfiguration(false, null, $cache); |
155
|
|
|
|
156
|
|
|
$this->assertSame($cache, $config->getResultCacheImpl()); |
157
|
|
|
$this->assertSame($cache, $config->getMetadataCacheImpl()); |
158
|
|
|
$this->assertSame($cache, $config->getQueryCacheImpl()); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|