5
5
use Dyrynda \Database \Rules \EfficientUuidExists ;
6
6
use Ramsey \Uuid \Uuid ;
7
7
use Tests \Fixtures \EfficientUuidPost ;
8
- use Illuminate \Support \Facades \Validator ;
9
8
10
9
class EfficientUuidExistsRuleTest extends TestCase
11
10
{
@@ -15,41 +14,29 @@ public function it_passes_valid_existing_uuid()
15
14
/** @var \Tests\Fixtures\EfficientUuidPost $post */
16
15
$ post = factory (EfficientUuidPost::class)->create ();
17
16
18
- /** @var \Illuminate\Validation\Validator $v */
19
- $ v = Validator::make (
20
- ['uuid ' => $ post ->uuid ],
21
- ['uuid ' => new EfficientUuidExists (EfficientUuidPost::class)]
22
- );
17
+ $ rule = new EfficientUuidExists (EfficientUuidPost::class);
23
18
24
- $ this ->assertTrue ($ v ->passes ());
19
+ $ this ->assertTrue ($ rule ->passes (' uuid ' , $ post -> uuid ));
25
20
}
26
21
27
22
/** @test */
28
23
public function it_fails_on_non_existing_uuid ()
29
24
{
30
25
$ uuid = Uuid::uuid4 ();
31
26
32
- /** @var \Illuminate\Validation\Validator $v */
33
- $ v = Validator::make (
34
- ['uuid ' => $ uuid ->toString ()],
35
- ['uuid ' => new EfficientUuidExists (EfficientUuidPost::class)]
36
- );
27
+ $ rule = new EfficientUuidExists (EfficientUuidPost::class);
37
28
38
- $ this ->assertFalse ($ v ->passes ());
29
+ $ this ->assertFalse ($ rule ->passes (' post_id ' , $ uuid ));
39
30
}
40
31
41
32
/** @test */
42
33
public function it_fails_on_any_non_uuid_invalid_strings ()
43
34
{
44
35
$ uuid = "1235123564354633 " ;
45
36
46
- /** @var \Illuminate\Validation\Validator $v */
47
- $ v = Validator::make (
48
- ['uuid ' => $ uuid ],
49
- ['uuid ' => new EfficientUuidExists (EfficientUuidPost::class, 'uuid ' )]
50
- );
37
+ $ rule = new EfficientUuidExists (EfficientUuidPost::class, 'uuid ' );
51
38
52
- $ this ->assertFalse ($ v ->passes ());
39
+ $ this ->assertFalse ($ rule ->passes (' post_id ' , $ uuid ));
53
40
}
54
41
55
42
/** @test */
@@ -58,12 +45,8 @@ public function it_works_with_custom_uuid_column_name()
58
45
/** @var \Tests\Fixtures\EfficientUuidPost $post */
59
46
$ post = factory (EfficientUuidPost::class)->create ();
60
47
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
- );
48
+ $ rule = new EfficientUuidExists (EfficientUuidPost::class, 'custom_uuid ' );
66
49
67
- $ this ->assertTrue ($ v ->passes ());
50
+ $ this ->assertTrue ($ rule ->passes (' custom_uuid ' , $ post -> custom_uuid ));
68
51
}
69
52
}
0 commit comments