Add CityValidatorByName.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
4b3bf81c76
commit
9244aa11bc
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\NextValidatorByName;
|
||||||
|
use App\Models\City;
|
||||||
|
|
||||||
|
class CityValidatorByName extends NextValidatorByName
|
||||||
|
{
|
||||||
|
public function isCurrentValid(): bool
|
||||||
|
{
|
||||||
|
$count = City::where('name', $this->getName())->count();
|
||||||
|
|
||||||
|
return $count != 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\CityValidatorByName;
|
||||||
|
use App\Models\Validation\Validators\OkValidator;
|
||||||
|
|
||||||
|
class CityValidatorByNameTest extends TestCase
|
||||||
|
{
|
||||||
|
public function dataProvider() {
|
||||||
|
return [
|
||||||
|
'Invalid Case' => [
|
||||||
|
'name' => '',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
'Not Found Case' => [
|
||||||
|
'name' => '404 City',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
'Found Case' => [
|
||||||
|
'name' => 'testCity',
|
||||||
|
'isValid' => true,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpValidator(string $name): CityValidatorByName
|
||||||
|
{
|
||||||
|
return new CityValidatorByName($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