1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Exception; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\PropertyChangedListener; |
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
7
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata as DoctrineClassMetaData; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\Validation\EntityValidatorInterface; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Symfony\Component\Validator\ConstraintViolationList; |
12
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ValidationExceptionTest |
16
|
|
|
* |
17
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Exception |
18
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
19
|
|
|
*/ |
20
|
|
|
class ValidationExceptionTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ValidationException |
24
|
|
|
*/ |
25
|
|
|
private $exception; |
26
|
|
|
|
27
|
|
|
private $errors; |
28
|
|
|
|
29
|
|
|
private $entity; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
33
|
|
|
*/ |
34
|
|
|
public function setup() |
35
|
|
|
{ |
36
|
|
|
try { |
37
|
|
|
$this->errors = new ConstraintViolationList(); |
38
|
|
|
$this->entity = new class implements EntityInterface |
39
|
|
|
{ |
40
|
|
|
public function getId() |
41
|
|
|
{ |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function loadMetadata(DoctrineClassMetaData $metadata): void |
46
|
|
|
{ |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function getPlural(): string |
51
|
|
|
{ |
52
|
|
|
return ''; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function getSingular(): string |
56
|
|
|
{ |
57
|
|
|
return ''; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function getIdField(): string |
61
|
|
|
{ |
62
|
|
|
return ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getShortName(): string |
66
|
|
|
{ |
67
|
|
|
return ''; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function debug(int $level = 0): string |
71
|
|
|
{ |
72
|
|
|
return ''; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public static function loadValidatorMetaData(ValidatorClassMetaData $metadata): void |
76
|
|
|
{ |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function injectValidator(EntityValidatorInterface $validator) |
81
|
|
|
{ |
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function isValid(): bool |
86
|
|
|
{ |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function validate() |
91
|
|
|
{ |
92
|
|
|
return; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function validateProperty(string $propertyName) |
96
|
|
|
{ |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Adds a listener that wants to be notified about property changes. |
103
|
|
|
* |
104
|
|
|
* @param PropertyChangedListener $listener |
105
|
|
|
* |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
|
|
public function addPropertyChangedListener(PropertyChangedListener $listener): void |
109
|
|
|
{ |
110
|
|
|
return; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getGetters(): array |
114
|
|
|
{ |
115
|
|
|
return []; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getSetters(): array |
119
|
|
|
{ |
120
|
|
|
return []; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function notifyEmbeddablePrefixedProperties( |
124
|
|
|
string $embeddablePropertyName, |
125
|
|
|
?string $propName = null, |
126
|
|
|
$oldValue = null, |
127
|
|
|
$newValue = null |
128
|
|
|
): void { |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function ensureMetaDataIsSet(EntityManagerInterface $entityManager): void |
133
|
|
|
{ |
134
|
|
|
return; |
135
|
|
|
} |
136
|
|
|
}; |
137
|
|
|
throw new ValidationException($this->errors, $this->entity); |
138
|
|
|
} catch (ValidationException $e) { |
139
|
|
|
$this->exception = $e; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testGetInvalidEntity(): void |
144
|
|
|
{ |
145
|
|
|
$expected = $this->entity; |
146
|
|
|
$actual = $this->exception->getInvalidEntity(); |
147
|
|
|
self::assertSame($expected, $actual); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function testGetValidationErrors(): void |
151
|
|
|
{ |
152
|
|
|
$expected = $this->errors; |
153
|
|
|
$actual = $this->exception->getValidationErrors(); |
154
|
|
|
self::assertSame($expected, $actual); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|