Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 212c10b

Browse files
Update tests to use the EfficientUuidExists rule class
1 parent ca0ddcf commit 212c10b

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

tests/EfficientUuidExistsRuleTest.php

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,68 @@
22

33
namespace Tests;
44

5+
use Dyrynda\Database\Rules\EfficientUuidExists;
56
use Ramsey\Uuid\Uuid;
67
use Tests\Fixtures\EfficientUuidPost;
78
use Illuminate\Support\Facades\Validator;
8-
use Illuminate\Validation\Rule;
99

1010
class EfficientUuidExistsRuleTest extends TestCase
1111
{
12-
/** @test */
13-
public function it_passes_valid_existing_uuid()
14-
{
15-
/** @var \Tests\Fixtures\EfficientUuidPost $post */
16-
$post = factory(EfficientUuidPost::class)->create();
12+
/** @test */
13+
public function it_passes_valid_existing_uuid()
14+
{
15+
/** @var \Tests\Fixtures\EfficientUuidPost $post */
16+
$post = factory(EfficientUuidPost::class)->create();
1717

18-
/** @var \Illuminate\Validation\Validator $v */
19-
$v = Validator::make(
20-
['uuid' => $post->getRawOriginal('uuid')],
21-
['uuid' => Rule::exists(EfficientUuidPost::class)]
22-
);
18+
/** @var \Illuminate\Validation\Validator $v */
19+
$v = Validator::make(
20+
['uuid' => $post->uuid],
21+
['uuid' => new EfficientUuidExists(EfficientUuidPost::class)]
22+
);
2323

24-
$this->assertTrue($v->passes());
25-
}
24+
$this->assertTrue($v->passes());
25+
}
2626

27-
/** @test */
28-
public function it_fails_on_non_existing_uuid()
29-
{
30-
$uuid = Uuid::uuid4();
27+
/** @test */
28+
public function it_fails_on_non_existing_uuid()
29+
{
30+
$uuid = Uuid::uuid4();
3131

32-
/** @var \Illuminate\Validation\Validator $v */
33-
$v = Validator::make(
34-
['uuid' => $uuid->getBytes()],
35-
['uuid' => Rule::exists(EfficientUuidPost::class)]
36-
);
32+
/** @var \Illuminate\Validation\Validator $v */
33+
$v = Validator::make(
34+
['uuid' => $uuid->toString()],
35+
['uuid' => new EfficientUuidExists(EfficientUuidPost::class)]
36+
);
3737

38-
$this->assertFalse($v->passes());
39-
}
38+
$this->assertFalse($v->passes());
39+
}
4040

41-
/** @test */
42-
public function it_fails_on_any_non_uuid_invalid_strings()
43-
{
44-
$uuid = "1235123564354633";
41+
/** @test */
42+
public function it_fails_on_any_non_uuid_invalid_strings()
43+
{
44+
$uuid = "1235123564354633";
4545

46-
/** @var \Illuminate\Validation\Validator $v */
47-
$v = Validator::make(
48-
['uuid' => $uuid],
49-
['uuid' => Rule::exists(EfficientUuidPost::class, 'uuid')]
50-
);
46+
/** @var \Illuminate\Validation\Validator $v */
47+
$v = Validator::make(
48+
['uuid' => $uuid],
49+
['uuid' => new EfficientUuidExists(EfficientUuidPost::class, 'uuid')]
50+
);
5151

52-
$this->assertFalse($v->passes());
53-
}
52+
$this->assertFalse($v->passes());
53+
}
5454

55-
/** @test */
56-
public function it_works_with_custom_uuid_column_name()
57-
{
58-
/** @var \Tests\Fixtures\EfficientUuidPost $post */
59-
$post = factory(EfficientUuidPost::class)->create();
55+
/** @test */
56+
public function it_works_with_custom_uuid_column_name()
57+
{
58+
/** @var \Tests\Fixtures\EfficientUuidPost $post */
59+
$post = factory(EfficientUuidPost::class)->create();
6060

61-
/** @var \Illuminate\Validation\Validator $v */
62-
$v = Validator::make(
63-
['custom_uuid' => $post->getRawOriginal('custom_uuid')],
64-
['custom_uuid' => ['required', Rule::exists(EfficientUuidPost::class)]]
65-
);
61+
/** @var \Illuminate\Validation\Validator $v */
62+
$v = Validator::make(
63+
['custom_uuid' => $post->custom_uuid],
64+
['custom_uuid' => ['required', new EfficientUuidExists(EfficientUuidPost::class, 'custom_uuid')]]
65+
);
6666

67-
$this->assertTrue($v->passes());
68-
}
67+
$this->assertTrue($v->passes());
68+
}
6969
}

0 commit comments

Comments
 (0)