|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xsolve\AssociateTests\Functional\DoctrineOrm\Source; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Xsolve\Associate\DoctrineOrm\Metadata\MetadataAdapterProvider; |
|
7
|
|
|
use Xsolve\Associate\DoctrineOrm\Source\EntityClassHelper; |
|
8
|
|
|
use Xsolve\Associate\DoctrineOrm\Source\EntitySource; |
|
9
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\DataProvider; |
|
10
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\DataProviderInterface; |
|
11
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\DoctrineOrmHelper; |
|
12
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\Entity\Product; |
|
13
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\Entity\Store; |
|
14
|
|
|
use Xsolve\AssociateTests\Functional\DoctrineOrm\Mock\Entity\Variant; |
|
15
|
|
|
|
|
16
|
|
|
class EntityClassHelperTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var \Doctrine\ORM\EntityManagerInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $entityManager; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var DataProviderInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $dataProvider; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param object[] $entities |
|
30
|
|
|
* @param string $expectedClassName |
|
31
|
|
|
* |
|
32
|
|
|
* @dataProvider dataSetEntityClass |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testSetEntityClass(array $entities, string $expectedClassName): void |
|
35
|
|
|
{ |
|
36
|
|
|
$doctrineOrmHelper = new DoctrineOrmHelper(); |
|
37
|
|
|
$this->entityManager = $doctrineOrmHelper->getEntityManager(); |
|
38
|
|
|
|
|
39
|
|
|
$metadataAdapterProvider = new MetadataAdapterProvider($this->entityManager); |
|
40
|
|
|
$entityClassHelper = new EntityClassHelper($metadataAdapterProvider); |
|
41
|
|
|
|
|
42
|
|
|
$entitySource = new EntitySource($entities); |
|
43
|
|
|
$entityClassHelper->supplementEntitySource($entitySource); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals($expectedClassName, $entitySource->getEntityClass()); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertContains($expectedClassName, [ |
|
48
|
|
|
$entitySource->getClassMetadataAdapter()->getClassName(), |
|
49
|
|
|
$entitySource->getClassMetadataAdapter()->getRootClassName(), |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public function dataSetEntityClass(): array |
|
57
|
|
|
{ |
|
58
|
|
|
$this->dataProvider = new DataProvider(); |
|
59
|
|
|
|
|
60
|
|
|
return [ |
|
61
|
|
|
[ |
|
62
|
|
|
$this->dataProvider->getProducts(['s1p1', 's1p3', 's3p1']), |
|
63
|
|
|
Product::class, |
|
64
|
|
|
], |
|
65
|
|
|
[ |
|
66
|
|
|
$this->dataProvider->getStores(['s1', 's2']), |
|
67
|
|
|
Store::class, |
|
68
|
|
|
], |
|
69
|
|
|
[ |
|
70
|
|
|
$this->dataProvider->getVariants(['s3p1v1']), |
|
71
|
|
|
Variant::class, |
|
72
|
|
|
], |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param object[] $entities |
|
78
|
|
|
* |
|
79
|
|
|
* @dataProvider dataSetEntityClassIfNoCommonClassName |
|
80
|
|
|
* @expectedException \Exception |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testSetEntityClassIfNoCommonClassName(array $entities): void |
|
83
|
|
|
{ |
|
84
|
|
|
$doctrineOrmHelper = new DoctrineOrmHelper(); |
|
85
|
|
|
$this->entityManager = $doctrineOrmHelper->getEntityManager(); |
|
86
|
|
|
|
|
87
|
|
|
$metadataAdapterProvider = new MetadataAdapterProvider($this->entityManager); |
|
88
|
|
|
$entityClassHelper = new EntityClassHelper($metadataAdapterProvider); |
|
89
|
|
|
|
|
90
|
|
|
$entitySource = new EntitySource($entities); |
|
91
|
|
|
$entityClassHelper->supplementEntitySource($entitySource); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
public function dataSetEntityClassIfNoCommonClassName(): array |
|
98
|
|
|
{ |
|
99
|
|
|
$this->dataProvider = new DataProvider(); |
|
100
|
|
|
|
|
101
|
|
|
return [ |
|
102
|
|
|
[ |
|
103
|
|
|
[ |
|
104
|
|
|
$this->dataProvider->getProducts(['s1p1'])[0], |
|
105
|
|
|
$this->dataProvider->getStores(['s2'])[0], |
|
106
|
|
|
$this->dataProvider->getProducts(['s3p1'])[0], |
|
107
|
|
|
], |
|
108
|
|
|
], |
|
109
|
|
|
[ |
|
110
|
|
|
[ |
|
111
|
|
|
$this->dataProvider->getStores(['s1'])[0], |
|
112
|
|
|
$this->dataProvider->getStores(['s2'])[0], |
|
113
|
|
|
$this->dataProvider->getProducts(['s1p3'])[0], |
|
114
|
|
|
], |
|
115
|
|
|
], |
|
116
|
|
|
[ |
|
117
|
|
|
[ |
|
118
|
|
|
$this->dataProvider->getVariants(['s3p1v1'])[0], |
|
119
|
|
|
$this->dataProvider->getStores(['s1'])[0], |
|
120
|
|
|
$this->dataProvider->getProducts(['s2p1'])[0], |
|
121
|
|
|
], |
|
122
|
|
|
], |
|
123
|
|
|
[ |
|
124
|
|
|
[ |
|
125
|
|
|
new \stdClass(), |
|
126
|
|
|
new \stdClass(), |
|
127
|
|
|
], |
|
128
|
|
|
], |
|
129
|
|
|
]; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|