|
2 | 2 |
|
3 | 3 | namespace Tests;
|
4 | 4 |
|
| 5 | +use Dyrynda\Database\Rules\EfficientUuidExists; |
5 | 6 | use Ramsey\Uuid\Uuid;
|
6 | 7 | use Tests\Fixtures\EfficientUuidPost;
|
7 | 8 | use Illuminate\Support\Facades\Validator;
|
8 |
| -use Illuminate\Validation\Rule; |
9 | 9 |
|
10 | 10 | class EfficientUuidExistsRuleTest extends TestCase
|
11 | 11 | {
|
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(); |
17 | 17 |
|
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 | + ); |
23 | 23 |
|
24 |
| - $this->assertTrue($v->passes()); |
25 |
| - } |
| 24 | + $this->assertTrue($v->passes()); |
| 25 | + } |
26 | 26 |
|
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(); |
31 | 31 |
|
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 | + ); |
37 | 37 |
|
38 |
| - $this->assertFalse($v->passes()); |
39 |
| - } |
| 38 | + $this->assertFalse($v->passes()); |
| 39 | + } |
40 | 40 |
|
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"; |
45 | 45 |
|
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 | + ); |
51 | 51 |
|
52 |
| - $this->assertFalse($v->passes()); |
53 |
| - } |
| 52 | + $this->assertFalse($v->passes()); |
| 53 | + } |
54 | 54 |
|
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(); |
60 | 60 |
|
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 | + ); |
66 | 66 |
|
67 |
| - $this->assertTrue($v->passes()); |
68 |
| - } |
| 67 | + $this->assertTrue($v->passes()); |
| 68 | + } |
69 | 69 | }
|
0 commit comments