From c592931101a871f816b6f65c3def1fb048b537c3 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 5 Sep 2023 18:05:43 +0300 Subject: [PATCH] Add UserValidatorByMatrixUserName. --- .../UserValidatorByMatrixUserName.php | 17 +++++++ .../UserValidatorByMatrixUserNameTest.php | 44 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 app/Models/Validation/Validators/UserValidatorByMatrixUserName.php create mode 100644 tests/Feature/Validation/Validators/UserValidatorByMatrixUserNameTest.php diff --git a/app/Models/Validation/Validators/UserValidatorByMatrixUserName.php b/app/Models/Validation/Validators/UserValidatorByMatrixUserName.php new file mode 100644 index 0000000..e6ea91e --- /dev/null +++ b/app/Models/Validation/Validators/UserValidatorByMatrixUserName.php @@ -0,0 +1,17 @@ +getName())->count(); + + return $count != 0; + } +} + diff --git a/tests/Feature/Validation/Validators/UserValidatorByMatrixUserNameTest.php b/tests/Feature/Validation/Validators/UserValidatorByMatrixUserNameTest.php new file mode 100644 index 0000000..1fb0011 --- /dev/null +++ b/tests/Feature/Validation/Validators/UserValidatorByMatrixUserNameTest.php @@ -0,0 +1,44 @@ + [ + '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); + } +} +