1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
namespace Illuminate\Tests\Validation;
use Illuminate\Translation\ArrayLoader;
use Illuminate\Translation\Translator;
use Illuminate\Validation\Validator;
use PHPUnit\Framework\TestCase;
class ValidatorAfterRuleTest extends TestCase
{
public function testAfterAcceptsArrayOfRules()
{
$validator = new Validator(new Translator(new ArrayLoader, 'en'), [], []);
$validator->after([
fn ($validator) => $validator->errors()->add('closure', 'true'),
new InvokableAfterRule,
new AfterMethodRule,
])->messages()->messages();
$this->assertSame($validator->messages()->messages(), [
'closure' => ['true'],
'invokableAfterRule' => ['true'],
'afterMethodRule' => ['true'],
]);
}
}
class InvokableAfterRule
{
public function __invoke($validator)
{
$validator->errors()->add('invokableAfterRule', 'true');
}
}
class AfterMethodRule
{
public function __invoke()
{
//
}
public function after($validator)
{
$validator->errors()->add('afterMethodRule', 'true');
}
}
|