1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Tools; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
8
|
|
|
use Doctrine\Common\Cache\Cache; |
9
|
|
|
use Doctrine\ORM\Configuration; |
10
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
11
|
|
|
use Doctrine\ORM\Mapping\Driver\XmlDriver; |
12
|
|
|
use Doctrine\ORM\Tools\Setup; |
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
|
|
|
$this->originalAutoloaderCount = count(spl_autoload_functions()); |
23
|
|
|
$this->originalIncludePath = get_include_path(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function tearDown() |
27
|
|
|
{ |
28
|
|
|
if ( ! $this->originalIncludePath) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
set_include_path($this->originalIncludePath); |
33
|
|
|
|
34
|
|
|
foreach (spl_autoload_functions() as $i => $loader) { |
35
|
|
|
if ($i > $this->originalAutoloaderCount + 1) { |
36
|
|
|
spl_autoload_unregister($loader); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testDirectoryAutoload() |
42
|
|
|
{ |
43
|
|
|
Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../vendor/doctrine/common/lib"); |
44
|
|
|
|
45
|
|
|
self::assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testAnnotationConfiguration() |
49
|
|
|
{ |
50
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true); |
51
|
|
|
|
52
|
|
|
self::assertInstanceOf(Configuration::class, $config); |
53
|
|
|
self::assertEquals(sys_get_temp_dir(), $config->getProxyManagerConfiguration()->getProxiesTargetDir()); |
54
|
|
|
self::assertEquals('DoctrineProxies', $config->getProxyManagerConfiguration()->getProxiesNamespace()); |
55
|
|
|
self::assertInstanceOf(AnnotationDriver::class, $config->getMetadataDriverImpl()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testXMLConfiguration() |
59
|
|
|
{ |
60
|
|
|
$config = Setup::createXMLMetadataConfiguration([], true); |
61
|
|
|
|
62
|
|
|
self::assertInstanceOf(Configuration::class, $config); |
63
|
|
|
self::assertInstanceOf(XmlDriver::class, $config->getMetadataDriverImpl()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @group DDC-1350 |
68
|
|
|
*/ |
69
|
|
|
public function testConfigureProxyDir() |
70
|
|
|
{ |
71
|
|
|
$path = $this->makeTemporaryDirectory(); |
72
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true, $path); |
73
|
|
|
self::assertSame($path, $config->getProxyManagerConfiguration()->getProxiesTargetDir()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @group DDC-1350 |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testConfigureCache() |
80
|
|
|
{ |
81
|
|
|
$cache = new ArrayCache(); |
82
|
|
|
$config = Setup::createAnnotationMetadataConfiguration([], true, null, $cache); |
83
|
|
|
|
84
|
|
|
self::assertSame($cache, $config->getResultCacheImpl()); |
85
|
|
|
self::assertSame($cache, $config->getMetadataCacheImpl()); |
86
|
|
|
self::assertSame($cache, $config->getQueryCacheImpl()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @group DDC-3190 |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function testConfigureCacheCustomInstance() |
93
|
|
|
{ |
94
|
|
|
$cache = $this->createMock(Cache::class); |
95
|
|
|
$config = Setup::createConfiguration([], null, $cache); |
|
|
|
|
96
|
|
|
|
97
|
|
|
self::assertSame($cache, $config->getResultCacheImpl()); |
98
|
|
|
self::assertSame($cache, $config->getMetadataCacheImpl()); |
99
|
|
|
self::assertSame($cache, $config->getQueryCacheImpl()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function makeTemporaryDirectory() : string |
103
|
|
|
{ |
104
|
|
|
$path = \tempnam(\sys_get_temp_dir(), 'foo'); |
105
|
|
|
|
106
|
|
|
\unlink($path); |
107
|
|
|
\mkdir($path); |
108
|
|
|
|
109
|
|
|
return $path; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: