Compare commits
12
Commits
f85bc047b8
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e3b3234f | ||
|
|
5c40bc6bf3 | ||
|
|
85bd79e59c | ||
|
|
c592931101 | ||
|
|
32cc601868 | ||
|
|
4c1e0bec07 | ||
|
|
9244aa11bc | ||
|
|
4b3bf81c76 | ||
|
|
02cdb1f792 | ||
|
|
2b37a4c2e7 | ||
|
|
c415a77272 | ||
|
|
b43759f3f4 |
@@ -21,10 +21,10 @@ use App\DotsAPI\Fetcher\v2\AuthApiFetcher;
|
||||
use App\DotsAPI\Fetcher\v2\AuthApiSender;
|
||||
use App\Http\Resources\API\v2\CartItemCollection;
|
||||
|
||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
||||
use App\Models\Validation\CityValidationByName;
|
||||
use App\Models\Validation\Messages\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\UserInformativeValidatorByMatrixUserNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
@@ -119,13 +119,15 @@ class CartController extends Controller
|
||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||
$cityName = $request->input('cityName') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new CityInformativeValidatorByNameFactory($cityName))->create()
|
||||
];
|
||||
|
||||
$validator = new CityValidationByName($cityName);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
// Get objects
|
||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||
@@ -162,13 +164,15 @@ class CartController extends Controller
|
||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||
$companyName = $request->input('companyName') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new CompanyInformativeValidatorByNameFactory($companyName))->create()
|
||||
];
|
||||
|
||||
$validator = (new CompanyInformativeValidatorByNameFactory($companyName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
// Get objects
|
||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||
@@ -203,13 +207,15 @@ class CartController extends Controller
|
||||
$itemName = $request->input('itemName') ?? '';
|
||||
$itemCount = $request->input('itemCount') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new ItemInformativeValidatorByNameFactory($itemName))->create()
|
||||
];
|
||||
|
||||
$validator = (new ItemInformativeValidatorByNameFactory($itemName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
if($itemCount == 0)
|
||||
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\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
use App\Models\Company;
|
||||
|
||||
class City extends Model implements ValidationByNameInterface
|
||||
class City extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -64,16 +63,4 @@ class City extends Model implements ValidationByNameInterface
|
||||
{
|
||||
$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\BelongsToMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
class Company extends Model implements ValidationByNameInterface
|
||||
class Company extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -36,16 +34,4 @@ class Company extends Model implements ValidationByNameInterface
|
||||
|
||||
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\BelongsToMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
class Item extends Model implements ValidationByNameInterface
|
||||
class Item extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -88,17 +86,5 @@ class Item extends Model implements ValidationByNameInterface
|
||||
|
||||
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 Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
class User extends Authenticatable implements ValidationByNameInterface
|
||||
class User extends Authenticatable
|
||||
{
|
||||
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
|
||||
{
|
||||
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,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory;
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
||||
use App\Models\Validation\Validators\EmptyNameValidator;
|
||||
use App\Models\Validation\Validators\CompanyValidatorByName;
|
||||
|
||||
class CompanyInformativeValidatorByNameFactory extends InformativeValidatorFactory
|
||||
{
|
||||
protected array $messages;
|
||||
protected string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->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!!!',
|
||||
];
|
||||
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function create(): InformativeValidator
|
||||
{
|
||||
$okValidator = new OkInformativeValidator($this->messages['found']);
|
||||
|
||||
$nameValidator = new NextInformativeValidator(
|
||||
$this->messages['not_found'],
|
||||
new CompanyValidatorByName($this->name, $okValidator),
|
||||
$okValidator
|
||||
);
|
||||
|
||||
return new NextInformativeValidator(
|
||||
$this->messages['invalid_name'],
|
||||
new EmptyNameValidator($this->name, $nameValidator),
|
||||
$nameValidator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
abstract class InformativeValidatorFactory
|
||||
{
|
||||
abstract function create(): InformativeValidator;
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory;
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
||||
use App\Models\Validation\Validators\EmptyNameValidator;
|
||||
use App\Models\Validation\Validators\ItemValidatorByName;
|
||||
|
||||
class ItemInformativeValidatorByNameFactory extends InformativeValidatorFactory
|
||||
{
|
||||
protected array $messages;
|
||||
protected string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->messages = [
|
||||
'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->name = $name;
|
||||
}
|
||||
|
||||
function create(): InformativeValidator
|
||||
{
|
||||
$okValidator = new OkInformativeValidator($this->messages['found']);
|
||||
|
||||
$nameValidator = new NextInformativeValidator(
|
||||
$this->messages['not_found'],
|
||||
new ItemValidatorByName($this->name, $okValidator),
|
||||
$okValidator
|
||||
);
|
||||
|
||||
return new NextInformativeValidator(
|
||||
$this->messages['invalid_name'],
|
||||
new EmptyNameValidator($this->name, $nameValidator),
|
||||
$nameValidator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,13 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidatorByName;
|
||||
use App\Models\Company;
|
||||
|
||||
class CompanyValidatorByName extends Validator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
public function __construct(string $name, Validator $nextValidator)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
|
||||
class CompanyValidatorByName extends NextValidatorByName {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
$count = Company::where('name', $this->name)->count();
|
||||
$count = Company::where('name', $this->getName())->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class EmptyNameValidator extends Validator {
|
||||
class EmptyNameValidator extends NextValidator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
|
||||
+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);
|
||||
}
|
||||
}
|
||||
|
||||
+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\CompanyValidatorByName;
|
||||
|
||||
class CompanyInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->setMessages((new MessageByNameFactory('company'))->create());
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||
{
|
||||
return new CompanyValidatorByName($this->name, $okValidator);
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||
|
||||
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorFactory;
|
||||
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||
use App\Models\Validation\Validators\Informative\NextInformativeValidator;
|
||||
use App\Models\Validation\Validators\EmptyNameValidator;
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
abstract class InformativeValidatorByNameFactory extends InformativeValidatorFactory
|
||||
{
|
||||
protected array $messages;
|
||||
protected string $name;
|
||||
|
||||
public function setMessages(array $messages): void
|
||||
{
|
||||
$this->messages = $messages;
|
||||
}
|
||||
|
||||
public function getMessages(): array
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
abstract public function getValidatorByName(InformativeValidator $okValidator): Validator;
|
||||
|
||||
public function create(): InformativeValidator
|
||||
{
|
||||
$okValidator = new OkInformativeValidator($this->messages['found']);
|
||||
|
||||
$nameValidator = new NextInformativeValidator(
|
||||
$this->messages['not_found'],
|
||||
$this->getValidatorByName($okValidator),
|
||||
$okValidator
|
||||
);
|
||||
|
||||
return new NextInformativeValidator(
|
||||
$this->messages['invalid_name'],
|
||||
new EmptyNameValidator($this->name, $nameValidator),
|
||||
$nameValidator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+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;
|
||||
}
|
||||
|
||||
+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\ItemValidatorByName;
|
||||
|
||||
class ItemInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->setMessages((new MessageByNameFactory('item'))->create());
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||
{
|
||||
return new ItemValidatorByName($this->name, $okValidator);
|
||||
}
|
||||
}
|
||||
|
||||
+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
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
namespace App\Models\Validation\Validators\Informative;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?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;
|
||||
|
||||
class NextInformativeValidator extends InformativeValidator {
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?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;
|
||||
|
||||
class OkInformativeValidator extends InformativeValidator {
|
||||
@@ -2,22 +2,13 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidatorByName;
|
||||
use App\Models\Item;
|
||||
|
||||
class ItemValidatorByName extends Validator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
public function __construct(string $name, Validator $nextValidator)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
|
||||
class ItemValidatorByName extends NextValidatorByName {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
$count = Item::where('name', $this->name)->count();
|
||||
$count = Item::where('name', $this->getName())->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
abstract class NextValidator extends Validator {
|
||||
protected Validator $nextValidator;
|
||||
|
||||
public function setNextValidator(Validator $validator): void
|
||||
{
|
||||
$this->nextValidator = $validator;
|
||||
}
|
||||
|
||||
public function getNextValidator(): Validator
|
||||
{
|
||||
return $this->nextValidator;
|
||||
}
|
||||
|
||||
abstract public function isCurrentValid(): bool;
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->isCurrentValid() && $this->getNextValidator()->isValid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
abstract class NextValidatorByName extends NextValidator {
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name, Validator $nextValidator)
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->setNextValidator($nextValidator);
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
abstract public function isCurrentValid(): bool;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class OkValidator extends Validator {
|
||||
class OkValidator extends NextValidator {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class UpperRangeValidator extends Validator {
|
||||
class UpperRangeValidator extends NextValidator {
|
||||
private int $value;
|
||||
private int $rangeLimit;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
abstract class Validator {
|
||||
abstract public function isCurrentValid(): bool;
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->isCurrentValid() && $this->nextValidator->isValid();
|
||||
}
|
||||
abstract public function isValid(): bool;
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ class CartTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
|
||||
$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->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 App\Models\Validation\Messages\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
|
||||
class CompanyInformativeValidatorByNameFactoryTest extends TestCase
|
||||
{
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||
|
||||
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 App\Models\Validation\Messages\OkInformativeValidator;
|
||||
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||
|
||||
class OkInformativeValidatorTest extends TestCase
|
||||
{
|
||||
+2
-2
@@ -4,8 +4,8 @@ namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
||||
use App\Models\Validation\Validators\Informative\NextInformativeValidator;
|
||||
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
|
||||
use App\Models\Validation\Validators\UpperRangeValidator;
|
||||
use App\Models\Validation\Validators\OkValidator;
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
Reference in New Issue
Block a user