|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Mapado\RestClientSdk\Tests\Units\Mapping\Driver; |
|
6
|
|
|
|
|
7
|
|
|
use atoum; |
|
8
|
|
|
use Mapado\RestClientSdk\Mapping\Relation; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class AnnotationDriver |
|
12
|
|
|
* |
|
13
|
|
|
* @author Julien Deniau <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class AnnotationDriver extends atoum |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* testClassWithoutEntityAnnotation |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testClassWithoutEntityAnnotation() |
|
21
|
|
|
{ |
|
22
|
|
|
$this |
|
23
|
|
|
->given($this->newTestedInstance($this->getCacheDir(), true)) |
|
24
|
|
|
->then |
|
25
|
|
|
->if($mapping = $this->testedInstance->loadClassname('Mapado\RestClientSdk\Tests\Model\JsonLd\Client')) |
|
26
|
|
|
->array($mapping) |
|
27
|
|
|
->isEmpty() |
|
28
|
|
|
; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* testAnnotationDriver |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testAnnotationDriver() |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
|
|
->given($this->newTestedInstance($this->getCacheDir(), true)) |
|
38
|
|
|
->then |
|
39
|
|
|
->if($mapping = $this->testedInstance->loadClassname('Mapado\RestClientSdk\Tests\Model\JsonLd\Product')) |
|
40
|
|
|
->array($mapping) |
|
41
|
|
|
->size->isEqualTo(1) |
|
42
|
|
|
->object($classMetadata = current($mapping)) |
|
43
|
|
|
->isInstanceOf('Mapado\RestClientSdk\Mapping\ClassMetadata') |
|
44
|
|
|
->string($classMetadata->getKey()) |
|
45
|
|
|
->isEqualTo('product') |
|
46
|
|
|
|
|
47
|
|
|
->string($classMetadata->getModelName()) |
|
48
|
|
|
->isEqualTo('Mapado\RestClientSdk\Tests\Model\JsonLd\Product') |
|
49
|
|
|
|
|
50
|
|
|
->string($classMetadata->getRepositoryName()) |
|
51
|
|
|
->isEqualTo('Mapado\RestClientSdk\Test\Model\ModelRepository') |
|
52
|
|
|
|
|
53
|
|
|
->array($attributeList = $classMetadata->getAttributeList()) |
|
54
|
|
|
->size->isEqualTo(3) |
|
55
|
|
|
|
|
56
|
|
|
->object($attribute = current($attributeList)) |
|
57
|
|
|
->isInstanceOf('Mapado\RestClientSdk\Mapping\Attribute') |
|
58
|
|
|
|
|
59
|
|
|
->string($attribute->getSerializedKey()) |
|
60
|
|
|
->isEqualTo('id') |
|
61
|
|
|
|
|
62
|
|
|
->then($attribute = next($attributeList)) |
|
63
|
|
|
->string($attribute->getSerializedKey()) |
|
64
|
|
|
->isEqualTo('product_value') |
|
65
|
|
|
->string($attribute->getAttributeName()) |
|
66
|
|
|
->isEqualTo('value') |
|
67
|
|
|
; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testAnnotationDriverWithRelations() |
|
71
|
|
|
{ |
|
72
|
|
|
$this |
|
73
|
|
|
->given($this->newTestedInstance($this->getCacheDir(), true)) |
|
74
|
|
|
->then |
|
75
|
|
|
->if($mapping = $this->testedInstance->loadClassname('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart')) |
|
76
|
|
|
->array($mapping) |
|
77
|
|
|
->size->isEqualTo(1) |
|
78
|
|
|
->object($classMetadata = current($mapping)) |
|
79
|
|
|
->isInstanceOf('Mapado\RestClientSdk\Mapping\ClassMetadata') |
|
80
|
|
|
->string($classMetadata->getKey()) |
|
81
|
|
|
->isEqualTo('cart') |
|
82
|
|
|
|
|
83
|
|
|
->array($classMetadata->getAttributeList()) |
|
84
|
|
|
->size->isEqualTo(6) |
|
85
|
|
|
|
|
86
|
|
|
->array($classMetadata->getRelationList()) |
|
87
|
|
|
->size->isEqualTo(2) |
|
88
|
|
|
|
|
89
|
|
|
->string(current($classMetadata->getRelationList())->getType()) |
|
90
|
|
|
->isEqualTo(Relation::ONE_TO_MANY) |
|
91
|
|
|
|
|
92
|
|
|
->then |
|
93
|
|
|
->if($mapping = $this->testedInstance->loadClassname('Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem')) |
|
94
|
|
|
->array($mapping) |
|
95
|
|
|
->size->isEqualTo(1) |
|
96
|
|
|
->object($classMetadata = current($mapping)) |
|
97
|
|
|
->isInstanceOf('Mapado\RestClientSdk\Mapping\ClassMetadata') |
|
98
|
|
|
->string($classMetadata->getKey()) |
|
99
|
|
|
->isEqualTo('cart_item') |
|
100
|
|
|
|
|
101
|
|
|
->array($classMetadata->getAttributeList()) |
|
102
|
|
|
->size->isEqualTo(5) |
|
103
|
|
|
|
|
104
|
|
|
->array($classMetadata->getRelationList()) |
|
105
|
|
|
->size->isEqualTo(1) |
|
106
|
|
|
|
|
107
|
|
|
->then($relation = current($classMetadata->getRelationList())) |
|
108
|
|
|
->string($relation->getType()) |
|
109
|
|
|
->isEqualTo(Relation::MANY_TO_ONE) |
|
110
|
|
|
|
|
111
|
|
|
->string($relation->getTargetEntity()) |
|
112
|
|
|
->isEqualTo('Mapado\RestClientSdk\Tests\Model\JsonLd\Cart') |
|
113
|
|
|
; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testLoadDirectory() |
|
117
|
|
|
{ |
|
118
|
|
|
$this |
|
119
|
|
|
->given($this->newTestedInstance($this->getCacheDir(), true)) |
|
120
|
|
|
->then |
|
121
|
|
|
->if($mapping = $this->testedInstance->loadDirectory(__DIR__ . '/../../../Model/JsonLd')) |
|
122
|
|
|
->array($mapping) |
|
123
|
|
|
->size->isEqualTo(4) |
|
124
|
|
|
; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* getCacheDir |
|
129
|
|
|
* |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
private function getCacheDir() |
|
133
|
|
|
{ |
|
134
|
|
|
return __DIR__ . '/../../../cache/'; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|