Compare commits
9
Commits
2b37a4c2e7
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e3b3234f | ||
|
|
5c40bc6bf3 | ||
|
|
85bd79e59c | ||
|
|
c592931101 | ||
|
|
32cc601868 | ||
|
|
4c1e0bec07 | ||
|
|
9244aa11bc | ||
|
|
4b3bf81c76 | ||
|
|
02cdb1f792 |
@@ -21,10 +21,10 @@ use App\DotsAPI\Fetcher\v2\AuthApiFetcher;
|
|||||||
use App\DotsAPI\Fetcher\v2\AuthApiSender;
|
use App\DotsAPI\Fetcher\v2\AuthApiSender;
|
||||||
use App\Http\Resources\API\v2\CartItemCollection;
|
use App\Http\Resources\API\v2\CartItemCollection;
|
||||||
|
|
||||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
use App\Models\Validation\Validators\Informative\Factories\UserInformativeValidatorByMatrixUserNameFactory;
|
||||||
use App\Models\Validation\CityValidationByName;
|
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Messages\Factories\CompanyInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
class CartController extends Controller
|
class CartController extends Controller
|
||||||
{
|
{
|
||||||
@@ -119,13 +119,15 @@ class CartController extends Controller
|
|||||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||||
$cityName = $request->input('cityName') ?? '';
|
$cityName = $request->input('cityName') ?? '';
|
||||||
|
|
||||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
$validators = [
|
||||||
if(!$validator->isValid())
|
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||||
return response()->json($validator->getMessageMap());
|
(new CityInformativeValidatorByNameFactory($cityName))->create()
|
||||||
|
];
|
||||||
|
|
||||||
$validator = new CityValidationByName($cityName);
|
foreach($validators as $validator) {
|
||||||
if(!$validator->isValid())
|
if(!$validator->isValid())
|
||||||
return response()->json($validator->getMessageMap());
|
return response()->json($validator->getOkStatus());
|
||||||
|
}
|
||||||
|
|
||||||
// Get objects
|
// Get objects
|
||||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||||
@@ -162,13 +164,15 @@ class CartController extends Controller
|
|||||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||||
$companyName = $request->input('companyName') ?? '';
|
$companyName = $request->input('companyName') ?? '';
|
||||||
|
|
||||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
$validators = [
|
||||||
if(!$validator->isValid())
|
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||||
return response()->json($validator->getMessageMap());
|
(new CompanyInformativeValidatorByNameFactory($companyName))->create()
|
||||||
|
];
|
||||||
|
|
||||||
$validator = (new CompanyInformativeValidatorByNameFactory($companyName))->create();
|
foreach($validators as $validator) {
|
||||||
if(!$validator->isValid())
|
if(!$validator->isValid())
|
||||||
return response()->json($validator->getOkStatus());
|
return response()->json($validator->getOkStatus());
|
||||||
|
}
|
||||||
|
|
||||||
// Get objects
|
// Get objects
|
||||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||||
@@ -203,13 +207,15 @@ class CartController extends Controller
|
|||||||
$itemName = $request->input('itemName') ?? '';
|
$itemName = $request->input('itemName') ?? '';
|
||||||
$itemCount = $request->input('itemCount') ?? '';
|
$itemCount = $request->input('itemCount') ?? '';
|
||||||
|
|
||||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
$validators = [
|
||||||
if(!$validator->isValid())
|
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||||
return response()->json($validator->getMessageMap());
|
(new ItemInformativeValidatorByNameFactory($itemName))->create()
|
||||||
|
];
|
||||||
|
|
||||||
$validator = (new ItemInformativeValidatorByNameFactory($itemName))->create();
|
foreach($validators as $validator) {
|
||||||
if(!$validator->isValid())
|
if(!$validator->isValid())
|
||||||
return response()->json($validator->getOkStatus());
|
return response()->json($validator->getOkStatus());
|
||||||
|
}
|
||||||
|
|
||||||
if($itemCount == 0)
|
if($itemCount == 0)
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|||||||
+1
-14
@@ -7,10 +7,9 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
use App\Models\Validation\ValidationByNameInterface;
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
|
||||||
class City extends Model implements ValidationByNameInterface
|
class City extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
@@ -64,16 +63,4 @@ class City extends Model implements ValidationByNameInterface
|
|||||||
{
|
{
|
||||||
$this->companies()->detach($company_ids);
|
$this->companies()->detach($company_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isExistByName(string $name): bool
|
|
||||||
{
|
|
||||||
$count = City::where('name', $name)->count();
|
|
||||||
|
|
||||||
return $count != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function isNameValid(string $name): bool
|
|
||||||
{
|
|
||||||
return $name != '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-15
@@ -7,9 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
use App\Models\Validation\ValidationByNameInterface;
|
class Company extends Model
|
||||||
|
|
||||||
class Company extends Model implements ValidationByNameInterface
|
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
@@ -36,16 +34,4 @@ class Company extends Model implements ValidationByNameInterface
|
|||||||
|
|
||||||
return $count != 0;
|
return $count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isExistByName(string $name): bool
|
|
||||||
{
|
|
||||||
$count = Company::where('name', $name)->count();
|
|
||||||
|
|
||||||
return $count != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function isNameValid(string $name): bool
|
|
||||||
{
|
|
||||||
return $name != '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-15
@@ -7,9 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
use App\Models\Validation\ValidationByNameInterface;
|
class Item extends Model
|
||||||
|
|
||||||
class Item extends Model implements ValidationByNameInterface
|
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
@@ -88,17 +86,5 @@ class Item extends Model implements ValidationByNameInterface
|
|||||||
|
|
||||||
return $its_company->id == $company->id;
|
return $its_company->id == $company->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isExistByName(string $name): bool
|
|
||||||
{
|
|
||||||
$count = Item::where('name', $name)->count();
|
|
||||||
|
|
||||||
return $count != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function isNameValid(string $name): bool
|
|
||||||
{
|
|
||||||
return $name != '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-15
@@ -9,9 +9,7 @@ use Illuminate\Notifications\Notifiable;
|
|||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
use App\Models\Validation\ValidationByNameInterface;
|
class User extends Authenticatable
|
||||||
|
|
||||||
class User extends Authenticatable implements ValidationByNameInterface
|
|
||||||
{
|
{
|
||||||
use HasApiTokens, HasFactory, Notifiable;
|
use HasApiTokens, HasFactory, Notifiable;
|
||||||
|
|
||||||
@@ -29,18 +27,6 @@ class User extends Authenticatable implements ValidationByNameInterface
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static function isExistByName(string $name): bool
|
|
||||||
{
|
|
||||||
$count = User::where('matrix_username', $name)->count();
|
|
||||||
|
|
||||||
return $count != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function isNameValid(string $name): bool
|
|
||||||
{
|
|
||||||
return $name != '';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userAddresses(): HasMany
|
public function userAddresses(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(UserAddress::class);
|
return $this->hasMany(UserAddress::class);
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation;
|
|
||||||
|
|
||||||
use App\Models\Validation\ModelValidationByName;
|
|
||||||
use App\Models\Validation\Messages\CityMessagesFactory;
|
|
||||||
|
|
||||||
class CityValidationByName extends ModelValidationByName
|
|
||||||
{
|
|
||||||
public function __construct(string $name)
|
|
||||||
{
|
|
||||||
parent::__construct(
|
|
||||||
$name,
|
|
||||||
'App\Models\City',
|
|
||||||
(new CityMessagesFactory())->create(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
|
||||||
|
|
||||||
use App\Models\Validation\ValidationStatus;
|
|
||||||
|
|
||||||
class BaseMessages
|
|
||||||
{
|
|
||||||
protected array $messages;
|
|
||||||
|
|
||||||
public function __construct($messages)
|
|
||||||
{
|
|
||||||
$this->messages = $messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMessage($status): string
|
|
||||||
{
|
|
||||||
return match($status)
|
|
||||||
{
|
|
||||||
ValidationStatus::FOUND => $this->messages['found'],
|
|
||||||
ValidationStatus::NOT_FOUND => $this->messages['not_found'],
|
|
||||||
ValidationStatus::INVALID_NAME => $this->messages['invalid_name'],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
|
||||||
|
|
||||||
use App\Models\Validation\Messages\BaseMessages;
|
|
||||||
|
|
||||||
class CityMessagesFactory
|
|
||||||
{
|
|
||||||
protected array $messages = [
|
|
||||||
'found' => 'A city with the name is valid.',
|
|
||||||
'not_found' => 'A city with the name does not exist!!!',
|
|
||||||
'invalid_name' => 'The city name is empty, please, write the name!!!',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
return new BaseMessages($this->messages);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages\Factories;
|
|
||||||
|
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
|
||||||
|
|
||||||
abstract class InformativeValidatorFactory
|
|
||||||
{
|
|
||||||
abstract function create(): InformativeValidator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Messages\Factories;
|
||||||
|
|
||||||
|
use App\Models\Validation\Messages\Factories\MessageFactory;
|
||||||
|
|
||||||
|
class MessageByNameFactory extends MessageFactory
|
||||||
|
{
|
||||||
|
private string $name;
|
||||||
|
|
||||||
|
public function __construct(string $name)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'found' => "A $this->name with the name is valid.",
|
||||||
|
'not_found' => "A $this->name with the name does not exist!!!",
|
||||||
|
'invalid_name' => "The $this->name name is empty, please, write the name!!!",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Messages\Factories;
|
||||||
|
|
||||||
|
abstract class MessageFactory
|
||||||
|
{
|
||||||
|
abstract function create(): array;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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!!!",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
|
||||||
|
|
||||||
use App\Models\Validation\Messages\BaseMessages;
|
|
||||||
|
|
||||||
class UserMessagesFactory
|
|
||||||
{
|
|
||||||
protected array $messages = [
|
|
||||||
'found' => 'A user with the username is valid.',
|
|
||||||
'not_found' => 'A user with the username does not exist!!!',
|
|
||||||
'invalid_name' => 'The username is empty, please, write username!!!',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
return new BaseMessages($this->messages);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation;
|
|
||||||
|
|
||||||
use App\Models\Validation\ValidationByNameInterface;
|
|
||||||
use App\Models\Validation\ValidationStatus;
|
|
||||||
use App\Models\Validation\Messages\BaseMessages;
|
|
||||||
|
|
||||||
class ModelValidationByName
|
|
||||||
{
|
|
||||||
protected static BaseMessages $messages;
|
|
||||||
protected static string $className;
|
|
||||||
protected string $name;
|
|
||||||
|
|
||||||
public function __construct(string $name, string $className, BaseMessages $messages)
|
|
||||||
{
|
|
||||||
if (!in_array('App\Models\Validation\ValidationByNameInterface', class_implements($className)))
|
|
||||||
throw new \RuntimeException("$className does not implement the ValidationByNameInterface interface.");
|
|
||||||
|
|
||||||
$this->name = $name;
|
|
||||||
static::$className = $className;
|
|
||||||
static::$messages = $messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getStatus()
|
|
||||||
{
|
|
||||||
if(!call_user_func([static::$className, 'isNameValid'], $this->name))
|
|
||||||
return ValidationStatus::INVALID_NAME;
|
|
||||||
|
|
||||||
if(!call_user_func([static::$className, 'isExistByName'], $this->name))
|
|
||||||
return ValidationStatus::NOT_FOUND;
|
|
||||||
|
|
||||||
return ValidationStatus::FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMessageMap()
|
|
||||||
{
|
|
||||||
$status = $this->getStatus();
|
|
||||||
|
|
||||||
return [
|
|
||||||
$status->status() => static::$messages->getMessage($status)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isValid()
|
|
||||||
{
|
|
||||||
return $this->getStatus()->isOk();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation;
|
|
||||||
|
|
||||||
use App\Models\Validation\ModelValidationByName;
|
|
||||||
use App\Models\Validation\Messages\UserMessagesFactory;
|
|
||||||
|
|
||||||
class UserValidationByMatrixUsername extends ModelValidationByName
|
|
||||||
{
|
|
||||||
public function __construct(string $name)
|
|
||||||
{
|
|
||||||
parent::__construct(
|
|
||||||
$name,
|
|
||||||
'App\Models\User',
|
|
||||||
(new UserMessagesFactory())->create(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation;
|
|
||||||
|
|
||||||
interface ValidationByNameInterface {
|
|
||||||
public static function isNameValid(string $name);
|
|
||||||
|
|
||||||
public static function isExistByName(string $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Validation;
|
|
||||||
|
|
||||||
enum ValidationStatus
|
|
||||||
{
|
|
||||||
case FOUND;
|
|
||||||
case NOT_FOUND;
|
|
||||||
case INVALID_NAME;
|
|
||||||
|
|
||||||
public function value(): string
|
|
||||||
{
|
|
||||||
return match($this)
|
|
||||||
{
|
|
||||||
ValidationStatus::FOUND => 'found',
|
|
||||||
ValidationStatus::NOT_FOUND => 'not_found',
|
|
||||||
ValidationStatus::INVALID_NAME => 'invalid_name',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function status(): string
|
|
||||||
{
|
|
||||||
return match($this)
|
|
||||||
{
|
|
||||||
ValidationStatus::FOUND => 'ok',
|
|
||||||
ValidationStatus::NOT_FOUND => 'error',
|
|
||||||
ValidationStatus::INVALID_NAME => 'error',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isError(): bool
|
|
||||||
{
|
|
||||||
return $this->status() == 'error';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isOk(): bool
|
|
||||||
{
|
|
||||||
return $this->status() == 'ok';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -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\MessageByNameFactory;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
use App\Models\Validation\Validators\CityValidatorByName;
|
||||||
|
|
||||||
|
class CityInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||||
|
{
|
||||||
|
public function __construct(string $name)
|
||||||
|
{
|
||||||
|
$this->setMessages((new MessageByNameFactory('city'))->create());
|
||||||
|
|
||||||
|
$this->setName($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||||
|
{
|
||||||
|
return new CityValidatorByName($this->name, $okValidator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+5
-8
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages\Factories;
|
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
|
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||||
|
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
use App\Models\Validation\Validators\CompanyValidatorByName;
|
use App\Models\Validation\Validators\CompanyValidatorByName;
|
||||||
@@ -12,11 +13,7 @@ class CompanyInformativeValidatorByNameFactory extends InformativeValidatorByNam
|
|||||||
{
|
{
|
||||||
public function __construct(string $name)
|
public function __construct(string $name)
|
||||||
{
|
{
|
||||||
$this->setMessages([
|
$this->setMessages((new MessageByNameFactory('company'))->create());
|
||||||
'found' => 'A company with the name is valid.',
|
|
||||||
'not_found' => 'A company with the name does not exist!!!',
|
|
||||||
'invalid_name' => 'The company name is empty, please, write the name!!!',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->setName($name);
|
$this->setName($name);
|
||||||
}
|
}
|
||||||
+5
-5
@@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages\Factories;
|
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory;
|
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorFactory;
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
use App\Models\Validation\Validators\Informative\NextInformativeValidator;
|
||||||
use App\Models\Validation\Validators\EmptyNameValidator;
|
use App\Models\Validation\Validators\EmptyNameValidator;
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
|
|
||||||
|
abstract class InformativeValidatorFactory
|
||||||
|
{
|
||||||
|
abstract function create(): InformativeValidator;
|
||||||
|
}
|
||||||
|
|
||||||
+5
-8
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages\Factories;
|
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
|
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||||
|
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
use App\Models\Validation\Validators\ItemValidatorByName;
|
use App\Models\Validation\Validators\ItemValidatorByName;
|
||||||
@@ -12,11 +13,7 @@ class ItemInformativeValidatorByNameFactory extends InformativeValidatorByNameFa
|
|||||||
{
|
{
|
||||||
public function __construct(string $name)
|
public function __construct(string $name)
|
||||||
{
|
{
|
||||||
$this->setMessages([
|
$this->setMessages((new MessageByNameFactory('item'))->create());
|
||||||
'found' => 'A item with the name is valid.',
|
|
||||||
'not_found' => 'A item with the name does not exist!!!',
|
|
||||||
'invalid_name' => 'The item name is empty, please, write the name!!!',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->setName($name);
|
$this->setName($name);
|
||||||
}
|
}
|
||||||
+26
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
namespace App\Models\Validation\Validators\Informative;
|
||||||
|
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
namespace App\Models\Validation\Validators\Informative;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
|
||||||
class NextInformativeValidator extends InformativeValidator {
|
class NextInformativeValidator extends InformativeValidator {
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Validation\Messages;
|
namespace App\Models\Validation\Validators\Informative;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\InformativeValidator;
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
use App\Models\Validation\Validators\OkValidator;
|
use App\Models\Validation\Validators\OkValidator;
|
||||||
|
|
||||||
class OkInformativeValidator extends InformativeValidator {
|
class OkInformativeValidator extends InformativeValidator {
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ class CartTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'error' => 'The username is empty, please, write username!!!'
|
'error' => 'The username is invalid, please, check that you are registered or signed in!!!'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +321,7 @@ class CartTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'error' => 'The username is empty, please, write username!!!'
|
'error' => 'The username is invalid, please, check that you are registered or signed in!!!'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
<?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,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
|
||||||
|
|
||||||
class UserValidationTest extends TestCase
|
|
||||||
{
|
|
||||||
public function dataProvider() {
|
|
||||||
return [
|
|
||||||
'Invalid Case' => [
|
|
||||||
'name' => '',
|
|
||||||
'key' => 'error',
|
|
||||||
'message' => 'The username is empty, please, write username!!!',
|
|
||||||
'isValid' => false,
|
|
||||||
],
|
|
||||||
'Not Found Case' => [
|
|
||||||
'name' => '@kostia:test.com',
|
|
||||||
'key' => 'error',
|
|
||||||
'message' => 'A user with the username does not exist!!!',
|
|
||||||
'isValid' => false,
|
|
||||||
],
|
|
||||||
'Found Case' => [
|
|
||||||
'name' => '@test:test.com',
|
|
||||||
'key' => 'ok',
|
|
||||||
'message' => 'A user with the username is valid.',
|
|
||||||
'isValid' => true,
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataProvider
|
|
||||||
*/
|
|
||||||
public function testUserValidationWithName(string $name, string $key, string $message, bool $isValid): void
|
|
||||||
{
|
|
||||||
$validator = new UserValidationByMatrixUsername($name);
|
|
||||||
$json = $validator->getMessageMap();
|
|
||||||
|
|
||||||
$this->assertEquals($json[$key], $message);
|
|
||||||
$this->assertEquals($validator->isValid(), $isValid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
|
class CityInformativeValidatorByNameFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function dataProvider() {
|
||||||
|
return [
|
||||||
|
'Found Case' => [
|
||||||
|
'name' => 'testCity',
|
||||||
|
'key' => 'ok',
|
||||||
|
'message' => 'A city with the name is valid.',
|
||||||
|
'isValid' => true,
|
||||||
|
],
|
||||||
|
'Not Found Case' => [
|
||||||
|
'name' => '404 City',
|
||||||
|
'key' => 'error',
|
||||||
|
'message' => 'A city with the name does not exist!!!',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
'Invalid Case' => [
|
||||||
|
'name' => '',
|
||||||
|
'key' => 'error',
|
||||||
|
'message' => 'The city name is empty, please, write the name!!!',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProvider
|
||||||
|
*/
|
||||||
|
public function testValidatorFactory(string $name, string $key, string $message, bool $isValid): void
|
||||||
|
{
|
||||||
|
$factory = new CityInformativeValidatorByNameFactory($name);
|
||||||
|
$validator = $factory->create();
|
||||||
|
|
||||||
|
$this->assertEquals($validator->getMessage(), $message);
|
||||||
|
$this->assertEquals($validator->getOkStatus(), [$key => $message]);
|
||||||
|
$this->assertEquals($validator->isValid(), $isValid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -4,7 +4,7 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\Factories\CompanyInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
class CompanyInformativeValidatorByNameFactoryTest extends TestCase
|
class CompanyInformativeValidatorByNameFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
+1
-1
@@ -4,7 +4,7 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
class ItemInformativeValidatorByNameFactoryTest extends TestCase
|
class ItemInformativeValidatorByNameFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
+47
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
use App\Models\Validation\ValidationStatus;
|
|
||||||
use App\Models\Validation\Messages\BaseMessages;
|
|
||||||
|
|
||||||
class BaseMessagesTest extends TestCase
|
|
||||||
{
|
|
||||||
protected array $messages = [
|
|
||||||
'found' => 'ok',
|
|
||||||
'not_found' => '404',
|
|
||||||
'invalid_name' => 'invalid name',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected BaseMessages $base_messages;
|
|
||||||
|
|
||||||
public function dataProvider() {
|
|
||||||
return [
|
|
||||||
'Invalid Case' => [
|
|
||||||
'status' => ValidationStatus::INVALID_NAME,
|
|
||||||
'expected_message' => $this->messages['invalid_name'],
|
|
||||||
],
|
|
||||||
'Not Found Case' => [
|
|
||||||
'status' => ValidationStatus::NOT_FOUND,
|
|
||||||
'expected_message' => $this->messages['not_found'],
|
|
||||||
],
|
|
||||||
'Found Case' => [
|
|
||||||
'status' => ValidationStatus::FOUND,
|
|
||||||
'expected_message' => $this->messages['found'],
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->base_messages = new BaseMessages($this->messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataProvider
|
|
||||||
*/
|
|
||||||
public function testGetMessage($status, string $expected_message): void
|
|
||||||
{
|
|
||||||
$message = $this->base_messages->getMessage($status);
|
|
||||||
|
|
||||||
$this->assertEquals($expected_message, $message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||||
|
|
||||||
|
class MessageByNameFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreate(): void
|
||||||
|
{
|
||||||
|
$name = 'company';
|
||||||
|
$expected_messages = [
|
||||||
|
'found' => "A company with the name is valid.",
|
||||||
|
'not_found' => "A company with the name does not exist!!!",
|
||||||
|
'invalid_name' => "The company name is empty, please, write the name!!!",
|
||||||
|
];
|
||||||
|
|
||||||
|
$factory = new MessageByNameFactory($name);
|
||||||
|
|
||||||
|
$this->assertEquals($factory->create(), $expected_messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -4,7 +4,7 @@ namespace Tests\Unit;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||||
|
|
||||||
class OkInformativeValidatorTest extends TestCase
|
class OkInformativeValidatorTest extends TestCase
|
||||||
{
|
{
|
||||||
+2
-2
@@ -4,8 +4,8 @@ namespace Tests\Unit;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
use App\Models\Validation\Validators\Informative\NextInformativeValidator;
|
||||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||||
use App\Models\Validation\Validators\UpperRangeValidator;
|
use App\Models\Validation\Validators\UpperRangeValidator;
|
||||||
use App\Models\Validation\Validators\OkValidator;
|
use App\Models\Validation\Validators\OkValidator;
|
||||||
use App\Models\Validation\Validators\Validator;
|
use App\Models\Validation\Validators\Validator;
|
||||||
Reference in New Issue
Block a user