Compare commits

...
32 Commits
Author SHA1 Message Date
KKlochko 91e3b3234f Refactor to use InformativeValidators instead of ModelValidation.
continuous-integration/drone/push Build is passing
2023-09-08 14:01:36 +03:00
KKlochko 5c40bc6bf3 Refactor to use UserInformativeValidatorByMatrixUserNameFactory.
continuous-integration/drone/push Build is passing
2023-09-07 18:38:03 +03:00
KKlochko 85bd79e59c Add InformativeValidatorFactory and MessageFactory for User.
continuous-integration/drone/push Build is passing
2023-09-06 17:21:05 +03:00
KKlochko c592931101 Add UserValidatorByMatrixUserName.
continuous-integration/drone/push Build is passing
2023-09-05 18:05:43 +03:00
KKlochko 32cc601868 Add CityInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
2023-09-04 20:34:26 +03:00
KKlochko 4c1e0bec07 Refactor InformativeValidators to move the modules into Validators.
continuous-integration/drone/push Build is passing
2023-09-03 11:54:39 +03:00
KKlochko 9244aa11bc Add CityValidatorByName.
continuous-integration/drone/push Build is passing
2023-09-02 20:48:29 +03:00
KKlochko 4b3bf81c76 Refactor ValidatorByNameFactories to use MessageByNameFactory.
continuous-integration/drone/push Build is passing
2023-09-01 12:22:34 +03:00
KKlochko 02cdb1f792 Add MessageFactory, MessageByNameFactory. 2023-09-01 12:22:08 +03:00
KKlochko 2b37a4c2e7 Refactor ValidatorByNameFactories of Company and Item models.
continuous-integration/drone/push Build is passing
2023-08-31 13:05:49 +03:00
KKlochko c415a77272 Add InformativeValidatorByNameFactory. 2023-08-31 13:02:00 +03:00
KKlochko b43759f3f4 Refactor Validators.
continuous-integration/drone/push Build is passing
2023-08-30 17:28:24 +03:00
KKlochko f85bc047b8 Refactor to use CompanyInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
2023-08-29 17:02:59 +03:00
KKlochko a37992c2e9 Add CompanyInformativeValidatorByNameFactory. 2023-08-29 17:00:28 +03:00
KKlochko 36a803131e Refactor to use ItemInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
2023-08-28 14:28:14 +03:00
KKlochko 9a83b398c0 Add ItemInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
2023-08-28 14:17:17 +03:00
KKlochko e057d2de27 Add EmptyNameValidator and ItemValidatorByName. 2023-08-27 20:31:26 +03:00
KKlochko 3ffc82ee7c Refactor InformativeValidator. 2023-08-27 20:25:43 +03:00
KKlochko 7662d98bce Add Informative Validators.
continuous-integration/drone/push Build is passing
2023-08-26 20:30:25 +03:00
KKlochko da847273b8 Update Validators to extend ABC instead of implementing interface. 2023-08-26 19:55:27 +03:00
KKlochko a4c0b3463b Add a validator interface, UpperRangeValidator and OkValidator.
continuous-integration/drone/push Build is passing
2023-08-25 20:48:23 +03:00
KKlochko 4430b04f11 Add UserAddress model.
continuous-integration/drone/push Build is passing
2023-08-24 17:58:33 +03:00
KKlochko 66b8373da3 Add the test for BaseMessages.
continuous-integration/drone/push Build is passing
2023-08-21 16:54:28 +03:00
KKlochko 8fda7eae83 Refactor the validation tests and remove example test.
continuous-integration/drone/push Build is failing
2023-08-21 14:48:57 +03:00
KKlochko 8c62393d3f Add ItemValidationByName.
continuous-integration/drone/push Build is passing
2023-08-20 11:14:23 +03:00
KKlochko c9974b007a Add UserValidationByMatrixUsername.
continuous-integration/drone/push Build is passing
2023-08-19 12:19:24 +03:00
KKlochko 1a7c585aa7 Add CityValidationByName.
continuous-integration/drone/push Build is passing
2023-08-18 13:20:09 +03:00
KKlochko f437d777a5 Add ValidationByName and CompanyValidationByName.
continuous-integration/drone/push Build is passing
2023-08-17 19:22:10 +03:00
KKlochko 135f4c0c93 Refactor the Company and its validator test.
continuous-integration/drone/push Build is passing
2023-08-16 18:12:29 +03:00
KKlochko c22945926c Refactor the City, Company and their tests.
continuous-integration/drone/push Build is passing
2023-08-16 17:47:22 +03:00
KKlochko a4938eb099 Add tests for City methods.
continuous-integration/drone/push Build is failing
2023-08-15 13:16:16 +03:00
KKlochko 394f821d35 Refactor the City and its tests. 2023-08-15 13:15:24 +03:00
52 changed files with 1441 additions and 244 deletions
+29 -24
View File
@@ -21,6 +21,11 @@ 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\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 class CartController extends Controller
{ {
/** /**
@@ -114,15 +119,15 @@ class CartController extends Controller
$matrixUsername = $request->input('matrixUsername') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
$cityName = $request->input('cityName') ?? ''; $cityName = $request->input('cityName') ?? '';
// check for not valid user $validators = [
$validation = User::validateWithMatrixUsername($matrixUsername); (new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
if(array_key_exists('error', $validation)) (new CityInformativeValidatorByNameFactory($cityName))->create()
return response()->json($validation); ];
// check for not valid city foreach($validators as $validator) {
$validation = City::validate_with_name($cityName); if(!$validator->isValid())
if(array_key_exists('error', $validation)) return response()->json($validator->getOkStatus());
return response()->json($validation); }
// Get objects // Get objects
$user = User::where('matrix_username', $matrixUsername)->first(); $user = User::where('matrix_username', $matrixUsername)->first();
@@ -159,15 +164,15 @@ class CartController extends Controller
$matrixUsername = $request->input('matrixUsername') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
$companyName = $request->input('companyName') ?? ''; $companyName = $request->input('companyName') ?? '';
// check for not valid user $validators = [
$validation = User::validateWithMatrixUsername($matrixUsername); (new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
if(array_key_exists('error', $validation)) (new CompanyInformativeValidatorByNameFactory($companyName))->create()
return response()->json($validation); ];
// check for not valid company foreach($validators as $validator) {
$validation = Company::validate_with_name($companyName); if(!$validator->isValid())
if(array_key_exists('error', $validation)) return response()->json($validator->getOkStatus());
return response()->json($validation); }
// Get objects // Get objects
$user = User::where('matrix_username', $matrixUsername)->first(); $user = User::where('matrix_username', $matrixUsername)->first();
@@ -202,15 +207,15 @@ class CartController extends Controller
$itemName = $request->input('itemName') ?? ''; $itemName = $request->input('itemName') ?? '';
$itemCount = $request->input('itemCount') ?? ''; $itemCount = $request->input('itemCount') ?? '';
// check for not valid user $validators = [
$validation = User::validateWithMatrixUsername($matrixUsername); (new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
if(array_key_exists('error', $validation)) (new ItemInformativeValidatorByNameFactory($itemName))->create()
return response()->json($validation); ];
// check for not valid item foreach($validators as $validator) {
$validation = Item::validate_with_name($itemName); if(!$validator->isValid())
if(array_key_exists('error', $validation)) return response()->json($validator->getOkStatus());
return response()->json($validation); }
if($itemCount == 0) if($itemCount == 0)
return response()->json([ return response()->json([
+14 -23
View File
@@ -5,6 +5,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Models\Company;
class City extends Model class City extends Model
{ {
@@ -21,6 +24,11 @@ class City extends Model
return $this->belongsToMany(Company::class, 'cities_companies', 'city_id', 'company_id'); return $this->belongsToMany(Company::class, 'cities_companies', 'city_id', 'company_id');
} }
public function userAddresses(): HasMany
{
return $this->hasMany(UserAddress::class);
}
public function getCompanyIds(): array public function getCompanyIds(): array
{ {
return $this->companies()->pluck('company_id')->toArray(); return $this->companies()->pluck('company_id')->toArray();
@@ -33,16 +41,20 @@ class City extends Model
public function addCompanyId(int $company_id) public function addCompanyId(int $company_id)
{ {
if(Company::isExist($company_id))
$this->addCompanyIds([$company_id]); $this->addCompanyIds([$company_id]);
} }
public function addCompanyIds(array $company_ids) public function addCompanyIds(array $company_ids)
{ {
$companyIDs = array_merge($this->getCompanyIds(), $company_ids); $existingCompanies = array_filter($company_ids, ['App\Models\Company', 'isExist']);
$companyIDs = array_merge($this->getCompanyIds(), $existingCompanies);
$this->companies()->sync($companyIDs); $this->companies()->sync($companyIDs);
} }
public function removeCompanyID(int $company_id) public function removeCompanyId(int $company_id)
{ {
$this->companies()->detach($company_id); $this->companies()->detach($company_id);
} }
@@ -51,25 +63,4 @@ class City extends Model
{ {
$this->companies()->detach($company_ids); $this->companies()->detach($company_ids);
} }
public static function validate_with_name(string $name)
{
$name = $name ?? '';
if($name == '')
return [
'error' => 'The city name is empty, please, write the name!!!'
];
$city = City::where('name', $name)->first();
if(!$city)
return [
'error' => 'A city with the name does not exist!!!'
];
return [
'ok' => 'A city with the name is valid.'
];
}
} }
+3 -17
View File
@@ -28,24 +28,10 @@ class Company extends Model
return $this->hasMany(Category::class); return $this->hasMany(Category::class);
} }
public static function validate_with_name(string $name) public static function isExist(int $id): bool
{ {
$name = $name ?? ''; $count = Company::where('id', $id)->count();
if($name == '') return $count != 0;
return [
'error' => 'The company name is empty, please, write the name!!!'
];
$company = company::where('name', $name)->first();
if(!$company)
return [
'error' => 'A company with the name does not exist!!!'
];
return [
'ok' => 'A company with the name is valid.'
];
} }
} }
-21
View File
@@ -86,26 +86,5 @@ class Item extends Model
return $its_company->id == $company->id; return $its_company->id == $company->id;
} }
public static function validate_with_name(string $name)
{
$name = $name ?? '';
if($name == '')
return [
'error' => 'The item name is empty, please, write the name!!!'
];
$item = Item::where('name', $name)->first();
if(!$item)
return [
'error' => 'A item with the name does not exist!!!'
];
return [
'ok' => 'A item with the name is valid.'
];
}
} }
+6 -18
View File
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens; use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Authenticatable class User extends Authenticatable
{ {
@@ -23,24 +24,11 @@ class User extends Authenticatable
'phone', 'phone',
]; ];
public static function validateWithMatrixUsername(string $matrixUsername)
public function userAddresses(): HasMany
{ {
$matrixUsername = $matrixUsername ?? ''; return $this->hasMany(UserAddress::class);
if($matrixUsername == '')
return [
'error' => 'The username is empty, please, write username!!!'
];
$user = User::where('matrix_username', $matrixUsername)->first();
if(!$user)
return [
'error' => 'A user with the username does not exist!!!'
];
return [
'ok' => 'A user with the username is valid.'
];
} }
} }
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserAddress extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'title',
'type',
'street',
'house',
'flat',
'stage',
'note',
'city_id',
'user_id',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function city(): BelongsTo
{
return $this->belongsTo(City::class);
}
}
@@ -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!!!",
];
}
}
@@ -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,16 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\NextValidatorByName;
use App\Models\Company;
class CompanyValidatorByName extends NextValidatorByName {
public function isCurrentValid(): bool
{
$count = Company::where('name', $this->getName())->count();
return $count != 0;
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\NextValidator;
class EmptyNameValidator extends NextValidator {
private string $name;
protected Validator $nextValidator;
public function __construct(string $name, Validator $nextValidator)
{
$this->name = $name;
$this->nextValidator = $nextValidator;
}
public function isCurrentValid(): bool
{
return $this->name != "";
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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
);
}
}
@@ -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;
}
@@ -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);
}
}
@@ -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);
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Models\Validation\Validators\Informative;
use App\Models\Validation\Validators\Validator;
abstract class InformativeValidator extends Validator {
protected Validator $validator;
protected string $message;
public function isCurrentValid(): bool
{
return $this->validator->isCurrentValid();
}
public function isValid(): bool
{
return $this->validator->isValid();
}
public function setValidator($validator): void
{
$this->validator = $validator;
}
public function setMessage($message): void
{
$this->message = $message;
}
public function getMessage(): string
{
if(!$this->isCurrentValid())
return $this->message;
return $this->nextValidator->getMessage();
}
public function getOkStatus(): array
{
if(!$this->isCurrentValid())
return ['error' => $this->message];
return $this->nextValidator->getOkStatus();
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Models\Validation\Validators\Informative;
use App\Models\Validation\Validators\Informative\InformativeValidator;
use App\Models\Validation\Validators\Validator;
class NextInformativeValidator extends InformativeValidator {
protected InformativeValidator $nextValidator;
public function __construct(string $message, Validator $validator, InformativeValidator $nextValidator)
{
$this->setMessage($message);
$this->setValidator($validator);
$this->nextValidator = $nextValidator;
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Models\Validation\Validators\Informative;
use App\Models\Validation\Validators\Informative\InformativeValidator;
use App\Models\Validation\Validators\OkValidator;
class OkInformativeValidator extends InformativeValidator {
public function __construct($message)
{
$this->message = $message;
$this->validator = new OkValidator();
}
public function getMessage(): string
{
return $this->message;
}
public function getOkStatus(): array
{
return ['ok' => $this->getMessage()];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\NextValidatorByName;
use App\Models\Item;
class ItemValidatorByName extends NextValidatorByName {
public function isCurrentValid(): bool
{
$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;
}
@@ -0,0 +1,18 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\NextValidator;
class OkValidator extends NextValidator {
public function isCurrentValid(): bool
{
return true;
}
public function isValid(): bool
{
return true;
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\NextValidator;
class UpperRangeValidator extends NextValidator {
private int $value;
private int $rangeLimit;
protected Validator $nextValidator;
public function __construct(int $value, int $rangeLimit, Validator $nextValidator)
{
$this->value = $value;
$this->rangeLimit = $rangeLimit;
$this->nextValidator = $nextValidator;
}
public function isCurrentValid(): bool
{
if($this->value > $this->rangeLimit)
return false;
return true;
}
}
@@ -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;
}
}
@@ -0,0 +1,8 @@
<?php
namespace App\Models\Validation\Validators;
interface ValidationInterface {
public function isValid(): bool;
}
@@ -0,0 +1,8 @@
<?php
namespace App\Models\Validation\Validators;
abstract class Validator {
abstract public function isValid(): bool;
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UserAddress>
*/
class UserAddressFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user_addresses', function (Blueprint $table) {
$table->id();
$table->string('title', 100);
$table->smallInteger('type')->default(0);
$table->string('street', 255);
$table->string('house', 10)->nullable();
$table->string('flat', 10)->nullable();
$table->string('stage', 10)->nullable();
$table->string('note', 100);
$table->unsignedBiginteger('city_id')->unsigned();
$table->unsignedBiginteger('user_id')->unsigned();
$table->foreign('city_id')->references('id')
->on('cities')->onDelete('cascade');
$table->foreign('user_id')->references('id')
->on('users')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_addresses');
}
};
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class UserAddressSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}
+2 -2
View File
@@ -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!!!'
]); ]);
} }
} }
+182 -16
View File
@@ -4,36 +4,202 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
use App\Models\City; use App\Models\City;
use App\Models\Company;
use function PHPUnit\Framework\assertNotNull;
class CityTest extends TestCase class CityTest extends TestCase
{ {
/* City validation */ use DatabaseTransactions;
public function test_city_with_empty_name(): void protected $city;
protected $company_ids = [];
public function setUpCityWithCompanies(): void
{ {
$json = City::validate_with_name(''); $this->setUpCity();
$this->setUpCompanyIds();
$this->assertEquals($json['error'], 'The city name is empty, please, write the name!!!'); $this->city->addCompanyIds($this->company_ids);
} }
public function test_not_existing_city_with_name(): void public function setUpCity(): void
{
$name = '404 City';
$json = City::validate_with_name($name);
$this->assertEquals($json['error'], 'A city with the name does not exist!!!');
}
public function test_valid_city_with_name(): void
{ {
$name = 'testCity'; $name = 'testCity';
$this->city = City::where('name', $name)->first();
}
$json = City::validate_with_name($name); public function setUpCompanyIds(): void
{
$company_names = ['testCompany', 'testCompany2'];
$this->company_ids = [];
$this->assertEquals($json['ok'], 'A city with the name is valid.'); foreach($company_names as $name) {
$company = Company::where('name', $name)->first();
array_push($this->company_ids, $company->id);
}
}
public function testGetCompanyIdsForEmptyCity()
{
$this->setUpCity();
$this->assertNotNull($this->city);
$this->assertIsArray($this->city->getCompanyIds());
$this->assertEquals($this->city->getCompanyIds(), []);
}
public function testAddTwoCompanyId()
{
$this->setUpCity();
$this->setUpCompanyIds();
foreach($this->company_ids as $id)
$this->city->addCompanyId($id);
$this->assertNotNull($this->city);
$this->assertIsArray($this->city->getCompanyIds());
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testAddNonExistingCompanyId()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->AddCompanyId(23423);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testAddNonExistingCompanyIdForEmptyCity()
{
$this->setUpCity();
$this->company_ids = [];
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->addCompanyId(23423);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testAddTwoCompanyIds()
{
$this->setUpCity();
$this->setUpCompanyIds();
$this->city->addCompanyIds($this->company_ids);
$this->assertNotNull($this->city);
$this->assertIsArray($this->city->getCompanyIds());
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testAddNonExistingCompanyIds()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->addCompanyIds([23423, 1234]);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testAddNonExistingCompanyIdsForEmpty()
{
$this->setUpCity();
$this->company_ids = [];
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->addCompanyIds([23423, 1234]);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testRemoveCompanyId()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyId($this->company_ids[1]);
$this->assertEquals($this->city->getCompanyIds(), [$this->company_ids[0]]);
}
public function testRemoveNonExistingCompanyId()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyId(23423);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testRemoveNonExistingCompanyIdForEmptyCity()
{
$this->setUpCity();
$this->company_ids = [];
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyId(23423);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testRemoveCompanyIds()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyIds([$this->company_ids[1]]);
$this->assertEquals($this->city->getCompanyIds(), [$this->company_ids[0]]);
}
public function testRemoveTwoCompanyIds()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyIds($this->company_ids);
$this->assertEquals($this->city->getCompanyIds(), []);
}
public function testRemoveNonExistingCompanyIds()
{
$this->setUpCityWithCompanies();
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyIds([23423, 1234]);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
}
public function testRemoveNonExistingCompanyIdsForEmptyCity()
{
$this->setUpCity();
$this->company_ids = [];
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
$this->city->removeCompanyIds([23423, 1234]);
$this->assertEquals($this->city->getCompanyIds(), $this->company_ids);
} }
} }
+13 -21
View File
@@ -10,30 +10,22 @@ use App\Models\Company;
class CompanyTest extends TestCase class CompanyTest extends TestCase
{ {
/* company validation */ public function testIsExistForExistingCompany()
public function test_company_with_empty_name(): void
{
$json = Company::validate_with_name('');
$this->assertEquals($json['error'], 'The company name is empty, please, write the name!!!');
}
public function test_not_existing_company_with_name(): void
{
$name = '404 Company';
$json = Company::validate_with_name($name);
$this->assertEquals($json['error'], 'A company with the name does not exist!!!');
}
public function test_valid_company_with_name(): void
{ {
$name = 'testCompany'; $name = 'testCompany';
$id = Company::where('name', $name)->first()->id;
$json = Company::validate_with_name($name); $isExist = Company::isExist($id);
$this->assertEquals($json['ok'], 'A company with the name is valid.'); $this->assertTrue($isExist);
}
public function testIsExistForNonExistingCompany()
{
$id = 1234;
$isExist = Company::isExist($id);
$this->assertFalse($isExist);
} }
} }
-19
View File
@@ -1,19 +0,0 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
-27
View File
@@ -38,31 +38,4 @@ class ItemTest extends TestCase
$this->assertFalse($is_belong); $this->assertFalse($is_belong);
} }
/* Item validation */
public function test_item_with_empty_name(): void
{
$json = Item::validate_with_name('');
$this->assertEquals($json['error'], 'The item name is empty, please, write the name!!!');
}
public function test_not_existing_item_with_name(): void
{
$name = '404 Item';
$json = Item::validate_with_name($name);
$this->assertEquals($json['error'], 'A item with the name does not exist!!!');
}
public function test_valid_item_with_name(): void
{
$name = 'Pizza Polo';
$json = Item::validate_with_name($name);
$this->assertEquals($json['ok'], 'A item with the name is valid.');
}
} }
@@ -1,39 +0,0 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Http\Request;
use App\Models\User;
class UserValidationTest extends TestCase
{
public function testEmptyUsernameWithMatrixUsername(): void
{
$json = User::validateWithMatrixUsername('');
$this->assertEquals($json['error'], 'The username is empty, please, write username!!!');
}
public function testValidUserWithMatrixUsername(): void
{
$matrixUsername = '@test:test.com';
$json = User::validateWithMatrixUsername($matrixUsername);
$this->assertEquals($json['ok'], 'A user with the username is valid.');
}
public function testNotExistingUserWithMatrixUsername(): void
{
$matrixUsername = '@kostia:test.com';
$json = User::validateWithMatrixUsername($matrixUsername);
$this->assertEquals($json['error'], 'A user with the username does not exist!!!');
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -0,0 +1,46 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
class CompanyInformativeValidatorByNameFactoryTest extends TestCase
{
public function dataProvider() {
return [
'Found Case' => [
'name' => 'testCompany',
'key' => 'ok',
'message' => 'A company with the name is valid.',
'isValid' => true,
],
'Not Found Case' => [
'name' => '404 Company',
'key' => 'error',
'message' => 'A company with the name does not exist!!!',
'isValid' => false,
],
'Invalid Case' => [
'name' => '',
'key' => 'error',
'message' => 'The company 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 CompanyInformativeValidatorByNameFactory($name);
$validator = $factory->create();
$this->assertEquals($validator->getMessage(), $message);
$this->assertEquals($validator->getOkStatus(), [$key => $message]);
$this->assertEquals($validator->isValid(), $isValid);
}
}
@@ -0,0 +1,46 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
class ItemInformativeValidatorByNameFactoryTest extends TestCase
{
public function dataProvider() {
return [
'Invalid Case' => [
'name' => '',
'key' => 'error',
'message' => 'The item name is empty, please, write the name!!!',
'isValid' => false,
],
'Not Found Case' => [
'name' => '404 Item',
'key' => 'error',
'message' => 'A item with the name does not exist!!!',
'isValid' => false,
],
'Found Case' => [
'name' => 'Pizza Polo',
'key' => 'ok',
'message' => 'A item with the name is valid.',
'isValid' => true,
]
];
}
/**
* @dataProvider dataProvider
*/
public function testValidatorFactory(string $name, string $key, string $message, bool $isValid): void
{
$factory = new ItemInformativeValidatorByNameFactory($name);
$validator = $factory->create();
$this->assertEquals($validator->getMessage(), $message);
$this->assertEquals($validator->getOkStatus(), [$key => $message]);
$this->assertEquals($validator->isValid(), $isValid);
}
}
@@ -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,43 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Validation\Validators\ItemValidatorByName;
use App\Models\Validation\Validators\OkValidator;
class ItemValidatorByNameTest extends TestCase
{
public function dataProvider() {
return [
'Invalid Case' => [
'name' => '',
'isValid' => false,
],
'Not Found Case' => [
'name' => '404 Item',
'isValid' => false,
],
'Found Case' => [
'name' => 'Pizza Polo',
'isValid' => true,
]
];
}
public function setUpValidator(string $name): ItemValidatorByName
{
return new ItemValidatorByName($name, new OkValidator());
}
/**
* @dataProvider dataProvider
*/
public function testGetMessage(string $name, bool $isValid): void
{
$validator = $this->setUpValidator($name);
$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);
}
}
-16
View File
@@ -1,16 +0,0 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}
@@ -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);
}
}
@@ -0,0 +1,39 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Models\Validation\Validators\EmptyNameValidator;
use App\Models\Validation\Validators\OkValidator;
class EmptyNameValidatorTest extends TestCase
{
public function dataProvider() {
return [
'Valid Case' => [
'name' => 'name',
'isValid' => true,
],
'Invalid Case' => [
'name' => '',
'isValid' => false,
],
];
}
public function setUpValidator(string $name): EmptyNameValidator
{
return new EmptyNameValidator($name, new OkValidator());
}
/**
* @dataProvider dataProvider
*/
public function testGetMessage(string $name, bool $isValid): void
{
$validator = $this->setUpValidator($name);
$this->assertEquals($validator->isValid(), $isValid);
}
}
@@ -0,0 +1,26 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Models\Validation\Validators\Informative\OkInformativeValidator;
class OkInformativeValidatorTest extends TestCase
{
public function testIsValid(): void
{
$message = 'All fine';
$validator = new OkInformativeValidator($message);
$this->assertTrue($validator->isValid());
}
public function testGetMessage(): void
{
$message = 'All fine';
$validator = new OkInformativeValidator($message);
$this->assertEquals($validator->getMessage(), $message);
}
}
@@ -0,0 +1,70 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
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;
class UpperRangeInformativeValidatorTest extends TestCase
{
protected $messages = [
'ok' => 'valid',
'error' => 'invalid',
];
public function dataProvider() {
return [
'Valid Case for 10' => [
'value' => 10,
'limit' => 10,
'isValid' => true,
'message' => $this->messages['ok'],
],
'Valid Case for 255' => [
'value' => 0,
'limit' => 255,
'isValid' => true,
'message' => $this->messages['ok'],
],
'Invalid Case for 10' => [
'value' => 11,
'limit' => 10,
'isValid' => false,
'message' => $this->messages['error'],
],
'Invalid Case for 255' => [
'value' => 256,
'limit' => 255,
'isValid' => false,
'message' => $this->messages['error'],
],
];
}
public function setUpValidator(int $value, int $rangeLimit): NextInformativeValidator
{
$upperRangeValidator = new UpperRangeValidator($value, $rangeLimit, new OkValidator());
return new NextInformativeValidator(
$this->messages['error'],
$upperRangeValidator,
new OkInformativeValidator($this->messages['ok']),
);
}
/**
* @dataProvider dataProvider
*/
public function testGetMessage(int $value, int $limit, bool $isValid, string $message): void
{
$validator = $this->setUpValidator($value, $limit);
$this->assertEquals($validator->isValid(), $isValid);
$this->assertEquals($validator->getMessage(), $message);
}
}
@@ -0,0 +1,17 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Models\Validation\Validators\OkValidator;
class OkValidatorTest extends TestCase
{
public function testIsValid(): void
{
$validator = new OkValidator();
$this->assertTrue($validator->isValid());
}
}
@@ -0,0 +1,51 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Models\Validation\Validators\UpperRangeValidator;
use App\Models\Validation\Validators\OkValidator;
class UpperRangeValidatorTest extends TestCase
{
public function dataProvider() {
return [
'Valid Case for 10' => [
'value' => 10,
'limit' => 10,
'isValid' => true,
],
'Valid Case for 255' => [
'value' => 0,
'limit' => 255,
'isValid' => true,
],
'Invalid Case for 255' => [
'value' => 11,
'limit' => 10,
'isValid' => false,
],
'Invalid Case for 255' => [
'value' => 256,
'limit' => 255,
'isValid' => false,
],
];
}
public function setUpValidator(int $value, int $rangeLimit): UpperRangeValidator
{
return new UpperRangeValidator($value, $rangeLimit, new OkValidator());
}
/**
* @dataProvider dataProvider
*/
public function testGetMessage(int $value, int $limit, bool $isValid): void
{
$validator = $this->setUpValidator($value, $limit);
$this->assertEquals($validator->isValid(), $isValid);
}
}