mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
Although I love PHPT files, and I've done my fair share of making it easier to write them in this library, they're very slow, and running them has become a hindrance. I've been fidgeting with the idea of using Pest for a while, and I think it's the right tool for the job. I had to create a couple of functions to make it easier to run those tests, and now they're working really alright. I migrated all the PHPT files into Pest files -- I automated most of the work with a little script using "nikic/php-parser"; this commit should contain all the previous PHPT tests as Pest tests. The previous integration tests would take sixteen seconds, and the Pest tests take less than a second.
47 lines
1.9 KiB
PHP
47 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Respect\Validation\Message\Translator\ArrayTranslator;
|
|
use Respect\Validation\Validator;
|
|
use Respect\Validation\ValidatorDefaults;
|
|
|
|
test('Scenario #1', expectFullMessage(
|
|
function (): void {
|
|
ValidatorDefaults::setTranslator(new ArrayTranslator([
|
|
'All of the required rules must pass for {{name}}' => 'Todas as regras requeridas devem passar para {{name}}',
|
|
'The length of' => 'O comprimento de',
|
|
'{{name}} must be of type string' => '{{name}} deve ser do tipo string',
|
|
'{{name}} must be between {{minValue}} and {{maxValue}}' => '{{name}} deve possuir de {{minValue}} a {{maxValue}} caracteres',
|
|
'{{name}} must be a valid telephone number for country {{countryName|trans}}'
|
|
=> '{{name}} deve ser um número de telefone válido para o país {{countryName|trans}}',
|
|
'United States' => 'Estados Unidos',
|
|
]));
|
|
|
|
Validator::stringType()->lengthBetween(2, 15)->phone('US')->assert(0);
|
|
},
|
|
<<<'FULL_MESSAGE'
|
|
- Todas as regras requeridas devem passar para 0
|
|
- 0 must be a string
|
|
- O comprimento de 0 deve possuir de 2 a 15 caracteres
|
|
- 0 deve ser um número de telefone válido para o país Estados Unidos
|
|
FULL_MESSAGE,
|
|
));
|
|
|
|
test('Scenario #2', expectMessage(
|
|
function (): void {
|
|
ValidatorDefaults::setTranslator(new ArrayTranslator([
|
|
'years' => 'anos',
|
|
'The number of {{type|trans}} between now and' => 'O número de {{type|trans}} entre agora e',
|
|
'{{name}} must be equal to {{compareTo}}' => '{{name}} deve ser igual a {{compareTo}}',
|
|
]));
|
|
|
|
v::dateTimeDiff('years', v::equals(2))->assert('1972-02-09');
|
|
},
|
|
'O número de anos entre agora e 1972-02-09 deve ser igual a 2',
|
|
));
|