Add UserValidatorByMatrixUserName.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
32cc601868
commit
c592931101
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\NextValidatorByName;
|
||||
use App\Models\User;
|
||||
|
||||
class UserValidatorByMatrixUserName extends NextValidatorByName
|
||||
{
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
$count = User::where('matrix_username', $this->getName())->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Validation\Validators\UserValidatorByMatrixUserName;
|
||||
use App\Models\Validation\Validators\OkValidator;
|
||||
|
||||
class UserValidatorByMatrixUserNameTest extends TestCase
|
||||
{
|
||||
public function dataProvider() {
|
||||
return [
|
||||
'Found Case' => [
|
||||
'name' => '@test:test.com',
|
||||
'isValid' => true,
|
||||
],
|
||||
'Not Found Case' => [
|
||||
'name' => '@kostia:test.com',
|
||||
'isValid' => false,
|
||||
],
|
||||
'Invalid Case' => [
|
||||
'name' => '',
|
||||
'isValid' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function setUpValidator(string $name): UserValidatorByMatrixUserName
|
||||
{
|
||||
return new UserValidatorByMatrixUserName($name, new OkValidator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testGetMessage(string $name, bool $isValid): void
|
||||
{
|
||||
$validator = $this->setUpValidator($name);
|
||||
|
||||
$this->assertEquals($validator->isValid(), $isValid);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue