1
+ <?php
2
+ /*
3
+ * Copyright 2024 Cloud Creativity Limited
4
+ *
5
+ * Use of this source code is governed by an MIT-style
6
+ * license that can be found in the LICENSE file or at
7
+ * https://opensource.org/licenses/MIT.
8
+ */
9
+
10
+ declare (strict_types=1 );
11
+
12
+ namespace LaravelJsonApi \Core \Tests \Unit \Schema \Concerns ;
13
+
14
+ use LaravelJsonApi \Core \Schema \Concerns \MatchesIds ;
15
+ use PHPUnit \Framework \TestCase ;
16
+
17
+ class MatchesIdsTest extends TestCase
18
+ {
19
+ /**
20
+ * @return void
21
+ */
22
+ public function testItIsNumeric (): void
23
+ {
24
+ $ id = new class () {
25
+ use MatchesIds;
26
+ };
27
+
28
+ $ this ->assertSame ('[0-9]+ ' , $ id ->pattern ());
29
+ $ this ->assertTrue ($ id ->match ('1234 ' ));
30
+ $ this ->assertFalse ($ id ->match ('123A45 ' ));
31
+ }
32
+
33
+ /**
34
+ * @return void
35
+ */
36
+ public function testItIsUuid (): void
37
+ {
38
+ $ id = new class () {
39
+ use MatchesIds;
40
+ };
41
+
42
+ $ this ->assertSame ($ id , $ id ->uuid ());
43
+ $ this ->assertSame ('[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12} ' , $ id ->pattern ());
44
+ $ this ->assertTrue ($ id ->match ('fca1509e-9178-45fd-8a2b-ae819d34f7e6 ' ));
45
+ $ this ->assertFalse ($ id ->match ('fca1509e917845fd8a2bae819d34f7e6 ' ));
46
+ }
47
+
48
+ /**
49
+ * @return void
50
+ */
51
+ public function testItIsUlid (): void
52
+ {
53
+ $ id = new class () {
54
+ use MatchesIds;
55
+ };
56
+
57
+ $ this ->assertSame ($ id , $ id ->ulid ());
58
+ $ this ->assertSame ('[0-7][0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z]{25} ' , $ id ->pattern ());
59
+ $ this ->assertTrue ($ id ->match ('01HT4PA8AZC8Q30ZGC5PEWZP0E ' ));
60
+ $ this ->assertFalse ($ id ->match ('01HT4PA8AZC8Q30ZGC5PEWZP0 ' ));
61
+ }
62
+
63
+ /**
64
+ * @return void
65
+ */
66
+ public function testItIsCustom (): void
67
+ {
68
+ $ id = new class () {
69
+ use MatchesIds;
70
+ };
71
+
72
+ $ this ->assertSame ($ id , $ id ->matchAs ('[A-D]+ ' ));
73
+ $ this ->assertSame ('[A-D]+ ' , $ id ->pattern ());
74
+ $ this ->assertTrue ($ id ->match ('abcd ' ));
75
+ $ this ->assertTrue ($ id ->match ('ABCD ' ));
76
+ $ this ->assertFalse ($ id ->match ('abcde ' ));
77
+
78
+ $ this ->assertSame ($ id , $ id ->matchCase ());
79
+ $ this ->assertTrue ($ id ->match ('ABCD ' ));
80
+ $ this ->assertFalse ($ id ->match ('abcd ' ));
81
+ }
82
+ }
0 commit comments