forked from barbieswimcrew/zip-code-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipCodeTest.php
More file actions
85 lines (72 loc) · 2.63 KB
/
ZipCodeTest.php
File metadata and controls
85 lines (72 loc) · 2.63 KB
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
<?php
namespace ZipCodeValidator\Tests\Constraints;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Exception\InvalidOptionsException;
use Symfony\Component\Validator\Exception\MissingOptionsException;
use ZipCodeValidator\Constraints\ZipCode;
class ZipCodeTest extends TestCase
{
public function testMissingOptionsExceptionWhenIsoAndGetterIsEmpty(): void
{
$this->expectException(MissingOptionsException::class);
$constraint = new ZipCode(null);
}
public function testLegacyStringOptionSetsIso(): void
{
$constraint = new ZipCode('DE');
$this->assertSame('DE', $constraint->iso);
}
public function testLegacyArrayOptionsAreStillSupported(): void
{
$payload = new \stdClass();
$constraint = new ZipCode([
'iso' => 'GB',
'strict' => false,
'caseSensitiveCheck' => false,
'message' => 'Custom message',
'groups' => 'Address',
'payload' => $payload,
]);
$this->assertSame('GB', $constraint->iso);
$this->assertFalse($constraint->strict);
$this->assertFalse($constraint->caseSensitiveCheck);
$this->assertSame('Custom message', $constraint->message);
$this->assertSame(['Address'], $constraint->groups);
$this->assertSame($payload, $constraint->payload);
}
public function testNamedParametersAreSupported(): void
{
$constraint = new ZipCode(
iso: 'FR',
strict: false,
caseSensitiveCheck: false,
message: 'Another message',
groups: ['Checkout']
);
$this->assertSame('FR', $constraint->iso);
$this->assertFalse($constraint->strict);
$this->assertFalse($constraint->caseSensitiveCheck);
$this->assertSame('Another message', $constraint->message);
$this->assertSame(['Checkout'], $constraint->groups);
}
public function testNamedParametersTakePrecedenceOverLegacyOptionsArray(): void
{
$constraint = new ZipCode(
['iso' => 'DE', 'strict' => true],
iso: 'US',
strict: false
);
$this->assertSame('US', $constraint->iso);
$this->assertFalse($constraint->strict);
}
public function testUnknownLegacyOptionThrowsException(): void
{
$this->expectException(InvalidOptionsException::class);
new ZipCode(['foo' => 'bar', 'iso' => 'FR']);
}
public function testLegacyStringOptionCannotBeCombinedWithNamedIso(): void
{
$this->expectException(InvalidOptionsException::class);
new ZipCode('DE', iso: 'FR');
}
}