1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Proxy\Proxy as DeprecatedProxy; |
6
|
|
|
use Doctrine\ORM\Proxy\Proxy; |
7
|
|
|
use Doctrine\ORM\Proxy\ProxyFactory; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @coversNothing |
15
|
|
|
*/ |
16
|
|
|
class ProxiesTest extends AbstractLargeTest |
17
|
|
|
{ |
18
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_MEDIUM . '/ProxiesTest/'; |
19
|
|
|
|
20
|
|
|
protected static $buildOnce = true; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var ProxyFactory |
24
|
|
|
*/ |
25
|
|
|
private $proxyFactory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* It is a Proxy, the others are just to make PHPStan happy |
29
|
|
|
* |
30
|
|
|
* @var Proxy|DeprecatedProxy|EntityInterface |
31
|
|
|
*/ |
32
|
|
|
private $proxy; |
33
|
|
|
|
34
|
|
|
private $testEntityFqns; |
35
|
|
|
|
36
|
|
|
public function setup() |
37
|
|
|
{ |
38
|
|
|
parent::setup(); |
39
|
|
|
if (false === self::$built) { |
40
|
|
|
$this->getTestCodeGenerator() |
41
|
|
|
->copyTo(self::WORK_DIR); |
42
|
|
|
self::$built = true; |
43
|
|
|
} |
44
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
45
|
|
|
$this->setupProxyFactory(); |
46
|
|
|
$this->testEntityFqns = $this->getTestEntityFqns(); |
47
|
|
|
$this->proxyFactory->generateProxyClasses($this->getClassMetaDatas()); |
48
|
|
|
$testEntity = current($this->testEntityFqns); |
49
|
|
|
$this->getEntitySaver()->save($this->createEntity($testEntity)); |
50
|
|
|
$this->proxy = $this->proxyFactory->getProxy($testEntity, ['id' => 1]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function setupProxyFactory(): void |
54
|
|
|
{ |
55
|
|
|
$proxyDir = $this->copiedWorkDir . '/proxies'; |
56
|
|
|
mkdir($proxyDir, 0777, true); |
57
|
|
|
$this->proxyFactory = new ProxyFactory( |
58
|
|
|
$this->getEntityManager(), |
59
|
|
|
$proxyDir, |
60
|
|
|
$this->copiedRootNamespace . '\\Proxies' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function getClassMetaDatas(): array |
65
|
|
|
{ |
66
|
|
|
$return = []; |
67
|
|
|
$entityManager = $this->getEntityManager(); |
68
|
|
|
foreach ($this->testEntityFqns as $entityFqn) { |
69
|
|
|
$return[] = $entityManager->getClassMetadata($entityFqn); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function getTestEntityFqns(): array |
76
|
|
|
{ |
77
|
|
|
$copiedRootNamespace = $this->copiedRootNamespace; |
78
|
|
|
|
79
|
|
|
return \array_map( |
80
|
|
|
function (string $entityFqn) use ($copiedRootNamespace): string { |
81
|
|
|
return str_replace(TestCodeGenerator::TEST_PROJECT_ROOT_NAMESPACE, $copiedRootNamespace, $entityFqn); |
82
|
|
|
}, |
83
|
|
|
TestCodeGenerator::TEST_ENTITIES |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @test |
89
|
|
|
* @large |
90
|
|
|
*/ |
91
|
|
|
public function proxyObjectsCanGetGettersAndSetters() |
92
|
|
|
{ |
93
|
|
|
$expectedSetters = [ |
94
|
|
|
'setString', |
95
|
|
|
'setDatetime', |
96
|
|
|
'setFloat', |
97
|
|
|
'setDecimal', |
98
|
|
|
'setInteger', |
99
|
|
|
'setText', |
100
|
|
|
'setBoolean', |
101
|
|
|
'setJson', |
102
|
|
|
'setAttributesAddress', |
103
|
|
|
'setAttributesEmails', |
104
|
|
|
'addAttributesEmail', |
105
|
|
|
'setCompanyDirector', |
106
|
|
|
'setOrders', |
107
|
|
|
'addOrder', |
108
|
|
|
]; |
109
|
|
|
$actualSetters = $this->proxy->getSetters(); |
|
|
|
|
110
|
|
|
self::assertSame($expectedSetters, $actualSetters); |
111
|
|
|
$expectedGetters = [ |
112
|
|
|
'getId', |
113
|
|
|
'getString', |
114
|
|
|
'getDatetime', |
115
|
|
|
'getFloat', |
116
|
|
|
'getDecimal', |
117
|
|
|
'getInteger', |
118
|
|
|
'getText', |
119
|
|
|
'isBoolean', |
120
|
|
|
'getJson', |
121
|
|
|
'getAttributesAddress', |
122
|
|
|
'getAttributesEmails', |
123
|
|
|
'getCompanyDirector', |
124
|
|
|
'getOrders', |
125
|
|
|
]; |
126
|
|
|
$actualGetters = $this->proxy->getGetters(); |
|
|
|
|
127
|
|
|
self::assertSame($expectedGetters, $actualGetters); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.