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

Commit 7e46f93

Browse files
revert to testing EfficientUuidExists rule directly
1 parent 212c10b commit 7e46f93

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

tests/EfficientUuidExistsRuleTest.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Dyrynda\Database\Rules\EfficientUuidExists;
66
use Ramsey\Uuid\Uuid;
77
use Tests\Fixtures\EfficientUuidPost;
8-
use Illuminate\Support\Facades\Validator;
98

109
class EfficientUuidExistsRuleTest extends TestCase
1110
{
@@ -15,41 +14,29 @@ public function it_passes_valid_existing_uuid()
1514
/** @var \Tests\Fixtures\EfficientUuidPost $post */
1615
$post = factory(EfficientUuidPost::class)->create();
1716

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);
2318

24-
$this->assertTrue($v->passes());
19+
$this->assertTrue($rule->passes('uuid', $post->uuid));
2520
}
2621

2722
/** @test */
2823
public function it_fails_on_non_existing_uuid()
2924
{
3025
$uuid = Uuid::uuid4();
3126

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);
3728

38-
$this->assertFalse($v->passes());
29+
$this->assertFalse($rule->passes('post_id', $uuid));
3930
}
4031

4132
/** @test */
4233
public function it_fails_on_any_non_uuid_invalid_strings()
4334
{
4435
$uuid = "1235123564354633";
4536

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');
5138

52-
$this->assertFalse($v->passes());
39+
$this->assertFalse($rule->passes('post_id', $uuid));
5340
}
5441

5542
/** @test */
@@ -58,12 +45,8 @@ public function it_works_with_custom_uuid_column_name()
5845
/** @var \Tests\Fixtures\EfficientUuidPost $post */
5946
$post = factory(EfficientUuidPost::class)->create();
6047

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');
6649

67-
$this->assertTrue($v->passes());
50+
$this->assertTrue($rule->passes('custom_uuid', $post->custom_uuid));
6851
}
6952
}

0 commit comments

Comments
 (0)