-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractEnumConstraintTest.php
121 lines (101 loc) · 3.28 KB
/
AbstractEnumConstraintTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
declare(strict_types=1);
namespace Zlikavac32\SymfonyEnum\Tests\Validator\Constraints;
use LogicException;
use PHPUnit\Framework\TestCase;
use stdClass;
use Symfony\Component\Validator\Constraints\ChoiceValidator;
use Zlikavac32\SymfonyEnum\Tests\Fixtures\YesNoEnum;
use Zlikavac32\SymfonyEnum\Validator\Constraints\AbstractEnumConstraint;
class AbstractEnumConstraintTest extends TestCase
{
public function testThatEnumClassCanNotBeNull(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Enum class can not be null');
$this->create(null);
}
public function testThatEnumClassMustHaveEnumAsItsParent(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('stdClass does not have Zlikavac32\Enum\Enum as it\'s parent');
$this->create(stdClass::class);
}
public function testThatChoicesOptionMustNotBeSet(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Key choices is overridden internally so it should not be set from the outside');
$this->create(
[
'choices' => [
'YES',
],
]
);
}
public function testThatCallbackOptionMustNotBeSet(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Key callback is overridden internally so it should not be set from the outside');
$this->create(
[
'callback' => function () {
},
]
);
}
public function testThatStrictOptionMustNotBeSet(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Key strict is overridden internally so it should not be set from the outside');
$this->create(
[
'strict' => false,
]
);
}
public function testThatConstraintCanBeCreatedWithJustEnumClass(): void
{
$this->assertInstanceOf(AbstractEnumConstraint::class, $this->create(YesNoEnum::class));
}
public function testThatConstraintCanBeCreatedWithOptionsArray(): void
{
$this->assertInstanceOf(
AbstractEnumConstraint::class,
$this->create(
[
'enumClass' => YesNoEnum::class,
]
)
);
}
public function testThatDefaultOptionIsCorrect(): void
{
$this->assertSame('enumClass',
$this->create(YesNoEnum::class)
->getDefaultOption()
);
}
public function testThatValidatedByIsCorrect(): void
{
$this->assertSame(ChoiceValidator::class,
$this->create(YesNoEnum::class)
->validatedBy()
);
}
public function testThatRequiredOptionsAreCorrect(): void
{
$this->assertSame(['enumClass'],
$this->create(YesNoEnum::class)
->getRequiredOptions()
);
}
private function create($options): AbstractEnumConstraint
{
return new class (function (): array {
return ['YES'];
}, $options) extends AbstractEnumConstraint
{
};
}
}