mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +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.
71 lines
2.8 KiB
PHP
71 lines
2.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
test('Non-iterable', expectAll(
|
|
fn() => v::max(v::negative())->assert(null),
|
|
'`null` must be iterable',
|
|
'- `null` must be iterable',
|
|
['max' => '`null` must be iterable']
|
|
));
|
|
|
|
test('Empty', expectAll(
|
|
fn() => v::max(v::negative())->assert([]),
|
|
'The value must not be empty',
|
|
'- The value must not be empty',
|
|
['max' => 'The value must not be empty']
|
|
));
|
|
|
|
test('Default', expectAll(
|
|
fn() => v::max(v::negative())->assert([1, 2, 3]),
|
|
'As the maximum of `[1, 2, 3]`, 3 must be a negative number',
|
|
'- As the maximum of `[1, 2, 3]`, 3 must be a negative number',
|
|
['maxNegative' => 'As the maximum of `[1, 2, 3]`, 3 must be a negative number']
|
|
));
|
|
|
|
test('Inverted', expectAll(
|
|
fn() => v::not(v::max(v::negative()))->assert([-3, -2, -1]),
|
|
'As the maximum of `[-3, -2, -1]`, -1 must not be a negative number',
|
|
'- As the maximum of `[-3, -2, -1]`, -1 must not be a negative number',
|
|
['notMaxNegative' => 'As the maximum of `[-3, -2, -1]`, -1 must not be a negative number']
|
|
));
|
|
|
|
test('With wrapped name, default', expectAll(
|
|
fn() => v::max(v::negative()->setName('Wrapped'))->setName('Wrapper')->assert([1, 2, 3]),
|
|
'The maximum of Wrapped must be a negative number',
|
|
'- The maximum of Wrapped must be a negative number',
|
|
['maxNegative' => 'The maximum of Wrapped must be a negative number']
|
|
));
|
|
|
|
test('With wrapper name, default', expectAll(
|
|
fn() => v::max(v::negative())->setName('Wrapper')->assert([1, 2, 3]),
|
|
'The maximum of Wrapper must be a negative number',
|
|
'- The maximum of Wrapper must be a negative number',
|
|
['maxNegative' => 'The maximum of Wrapper must be a negative number']
|
|
));
|
|
|
|
test('With wrapped name, inverted', expectAll(
|
|
fn() => v::not(v::max(v::negative()->setName('Wrapped')))->setName('Wrapper')->assert([-3, -2, -1]),
|
|
'The maximum of Wrapped must not be a negative number',
|
|
'- The maximum of Wrapped must not be a negative number',
|
|
['notMaxNegative' => 'The maximum of Wrapped must not be a negative number']
|
|
));
|
|
|
|
test('With wrapper name, inverted', expectAll(
|
|
fn() => v::not(v::max(v::negative()))->setName('Wrapper')->assert([-3, -2, -1]),
|
|
'The maximum of Wrapper must not be a negative number',
|
|
'- The maximum of Wrapper must not be a negative number',
|
|
['notMaxNegative' => 'The maximum of Wrapper must not be a negative number']
|
|
));
|
|
|
|
test('With template, default', expectAll(
|
|
fn() => v::max(v::negative())->assert([1, 2, 3], 'The maximum of the value is not what we expect'),
|
|
'The maximum of the value is not what we expect',
|
|
'- The maximum of the value is not what we expect',
|
|
['maxNegative' => 'The maximum of the value is not what we expect']
|
|
));
|