This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Validation\CityValidationByName;
|
||||
|
||||
class CityValidationByNameTest extends TestCase
|
||||
{
|
||||
public function dataProvider() {
|
||||
return [
|
||||
'Invalid Case' => [
|
||||
'name' => '',
|
||||
'key' => 'error',
|
||||
'message' => 'The city name is empty, please, write the name!!!',
|
||||
'isValid' => false,
|
||||
],
|
||||
'Not Found Case' => [
|
||||
'name' => '404 City',
|
||||
'key' => 'error',
|
||||
'message' => 'A city with the name does not exist!!!',
|
||||
'isValid' => false,
|
||||
],
|
||||
'Found Case' => [
|
||||
'name' => 'testCity',
|
||||
'key' => 'ok',
|
||||
'message' => 'A city with the name is valid.',
|
||||
'isValid' => true,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testCityValidationWithName(string $name, string $key, string $message, bool $isValid): void
|
||||
{
|
||||
$validator = new CityValidationByName($name);
|
||||
$json = $validator->getMessageMap();
|
||||
|
||||
$this->assertEquals($json[$key], $message);
|
||||
$this->assertEquals($validator->isValid(), $isValid);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\City;
|
||||
|
||||
class CityValidationTest extends TestCase
|
||||
{
|
||||
public function testCityWithEmptyName(): void
|
||||
{
|
||||
$json = City::validateWithName('');
|
||||
|
||||
$this->assertEquals($json['error'], 'The city name is empty, please, write the name!!!');
|
||||
}
|
||||
|
||||
public function testNotExistingCityWithName(): void
|
||||
{
|
||||
$name = '404 City';
|
||||
|
||||
$json = City::validateWithName($name);
|
||||
|
||||
$this->assertEquals($json['error'], 'A city with the name does not exist!!!');
|
||||
}
|
||||
|
||||
public function testValidCityWithName(): void
|
||||
{
|
||||
$name = 'testCity';
|
||||
|
||||
$json = City::validateWithName($name);
|
||||
|
||||
$this->assertEquals($json['ok'], 'A city with the name is valid.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user