Add InformativeValidatorFactory and MessageFactory for User.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c592931101
commit
85bd79e59c
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\MessageFactory;
|
||||
|
||||
class UsernameMessageByNameFactory extends MessageFactory
|
||||
{
|
||||
public function create(): array
|
||||
{
|
||||
return [
|
||||
'found' => "A user with the username is valid.",
|
||||
'not_found' => "A user with the username does not exist!!!",
|
||||
'invalid_name' => "The username is invalid, please, check that you are registered or signed in!!!",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||
|
||||
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||
use App\Models\Validation\Messages\Factories\UsernameMessageByNameFactory;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\UserValidatorByMatrixUserName;
|
||||
|
||||
class UserInformativeValidatorByMatrixUserNameFactory extends InformativeValidatorByNameFactory
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->setMessages((new UsernameMessageByNameFactory())->create());
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||
{
|
||||
return new UserValidatorByMatrixUserName($this->name, $okValidator);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Validation\Validators\Informative\Factories\UserInformativeValidatorByMatrixUserNameFactory;
|
||||
|
||||
class UserInformativeValidatorByMatrixUserNameFactoryTest extends TestCase
|
||||
{
|
||||
public function dataProvider() {
|
||||
return [
|
||||
'Found Case' => [
|
||||
'name' => '@test:test.com',
|
||||
'key' => 'ok',
|
||||
'message' => 'A user with the username is valid.',
|
||||
'isValid' => true,
|
||||
],
|
||||
'Not Found Case' => [
|
||||
'name' => '@kostia:test.com',
|
||||
'key' => 'error',
|
||||
'message' => 'A user with the username does not exist!!!',
|
||||
'isValid' => false,
|
||||
],
|
||||
'Invalid Case' => [
|
||||
'name' => '',
|
||||
'key' => 'error',
|
||||
'message' => 'The username is invalid, please, check that you are registered or signed in!!!',
|
||||
'isValid' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testValidatorFactory(string $name, string $key, string $message, bool $isValid): void
|
||||
{
|
||||
$factory = new UserInformativeValidatorByMatrixUserNameFactory($name);
|
||||
$validator = $factory->create();
|
||||
|
||||
$this->assertEquals($validator->getMessage(), $message);
|
||||
$this->assertEquals($validator->getOkStatus(), [$key => $message]);
|
||||
$this->assertEquals($validator->isValid(), $isValid);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue