Skip to content

Commit 680d6ba

Browse files
committed
Remove conditional around invokable rule
1 parent e30ce8b commit 680d6ba

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

tests/Unit/ValidationRuleParsingTest.php

+14-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Knuckles\Scribe\Tools\DocumentationConfig;
1414
use Knuckles\Scribe\Tests\Fixtures;
1515

16-
$invokableRulesSupported = interface_exists(\Illuminate\Contracts\Validation\InvokableRule::class);
1716
$laravel10Rules = version_compare(Application::VERSION, '10.0', '>=');
1817

1918
class ValidationRuleParsingTest extends BaseLaravelTest
@@ -531,10 +530,7 @@ public function can_parse_custom_rule_classes()
531530
'param1' => ['bail', 'required', new DummyWithDocsValidationRule],
532531
];
533532

534-
global $invokableRulesSupported;
535-
if ($invokableRulesSupported) {
536-
$ruleset['param2'] = [new DummyInvokableValidationRule];
537-
}
533+
$ruleset['param2'] = [new DummyInvokableValidationRule];
538534
global $laravel10Rules;
539535
if ($laravel10Rules) {
540536
$ruleset['param3'] = [new DummyL10ValidationRule];
@@ -543,7 +539,7 @@ public function can_parse_custom_rule_classes()
543539
$results = $this->strategy->parse($ruleset);
544540
$this->assertEquals(true, $results['param1']['required']);
545541
$this->assertEquals('This is a dummy test rule.', $results['param1']['description']);
546-
if (isset($results['param2'])) $this->assertEquals('This rule is invokable.', $results['param2']['description']);
542+
$this->assertEquals('This rule is invokable.', $results['param2']['description']);
547543
if (isset($results['param3'])) $this->assertEquals('This is a custom rule.', $results['param3']['description']);
548544
}
549545

@@ -718,23 +714,22 @@ public static function docs()
718714
}
719715
}
720716

721-
if ($invokableRulesSupported) {
722-
class DummyInvokableValidationRule implements \Illuminate\Contracts\Validation\InvokableRule
717+
// Laravel 9 introduced InvokableRule
718+
class DummyInvokableValidationRule implements \Illuminate\Contracts\Validation\InvokableRule
719+
{
720+
public function __invoke($attribute, $value, $fail)
723721
{
724-
public function __invoke($attribute, $value, $fail)
725-
{
726-
if (strtoupper($value) !== $value) {
727-
$fail(':attribute must be uppercase.');
728-
}
722+
if (strtoupper($value) !== $value) {
723+
$fail(':attribute must be uppercase.');
729724
}
725+
}
730726

731-
public function docs()
732-
{
727+
public function docs()
728+
{
733729

734-
return [
735-
'description' => 'This rule is invokable.',
736-
];
737-
}
730+
return [
731+
'description' => 'This rule is invokable.',
732+
];
738733
}
739734
}
740735

0 commit comments

Comments
 (0)