Skip to content

Commit f6fed2a

Browse files
committed
Merge branch 'develop' into next
2 parents 34fcac2 + 41a1190 commit f6fed2a

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

src/Core/Schema/Concerns/MatchesIds.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
trait MatchesIds
1515
{
16-
1716
/**
1817
* @var string
1918
*/
@@ -39,7 +38,7 @@ public function pattern(): string
3938
*
4039
* @return $this
4140
*/
42-
public function uuid(): self
41+
public function uuid(): static
4342
{
4443
return $this->matchAs('[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}');
4544
}
@@ -49,7 +48,7 @@ public function uuid(): self
4948
*
5049
* @return $this
5150
*/
52-
public function ulid(): self
51+
public function ulid(): static
5352
{
5453
return $this->matchAs('[0-7][0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z]{25}');
5554
}
@@ -60,7 +59,7 @@ public function ulid(): self
6059
* @param string $pattern
6160
* @return $this
6261
*/
63-
public function matchAs(string $pattern): self
62+
public function matchAs(string $pattern): static
6463
{
6564
$this->pattern = $pattern;
6665

@@ -72,7 +71,7 @@ public function matchAs(string $pattern): self
7271
*
7372
* @return $this
7473
*/
75-
public function matchCase(): self
74+
public function matchCase(): static
7675
{
7776
$this->flags = 'D';
7877

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)