mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 10:40:24 +02:00
Use "iterable" for Data Providers of RuleTestCase
That enables more flexibility when creating data providers, allowing the use of generators, for example. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
a3c1602351
commit
c079ecbb7e
|
@ -110,30 +110,20 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
#[CoversClass(HelloWorld::class)]
|
||||
final class HelloWorldTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* @return array<array{HelloWorld, mixed}>
|
||||
*/
|
||||
public static function providerForValidInput(): array
|
||||
/** @return array<array{HelloWorld, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
$rule = new HelloWorld();
|
||||
|
||||
return [
|
||||
[$rule, 'Hello World'],
|
||||
];
|
||||
yield [new HelloWorld(), 'Hello World'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{HelloWorld, mixed}>
|
||||
*/
|
||||
public static function providerForInvalidInput(): array
|
||||
/** @return array<array{HelloWorld, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
$rule = new HelloWorld();
|
||||
|
||||
return [
|
||||
[$rule, 'Not a hello'],
|
||||
[$rule, 'Hello darkness, my old friend'],
|
||||
[$rule, 'Hello is it me you\'re looking for?'],
|
||||
];
|
||||
yield [$rule, 'Not a hello'];
|
||||
yield [$rule, 'Hello darkness, my old friend'];
|
||||
yield [$rule, 'Hello is it me you\'re looking for?'];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -30,9 +30,9 @@ abstract class RuleTestCase extends TestCase
|
|||
* as the first element and an input in which the validation SHOULD pass.
|
||||
*
|
||||
* @api
|
||||
* @return array<string|int, array{Validatable, mixed}>
|
||||
* @return iterable<string|int, array{Validatable, mixed}>
|
||||
*/
|
||||
abstract public static function providerForValidInput(): array;
|
||||
abstract public static function providerForValidInput(): iterable;
|
||||
|
||||
/**
|
||||
* Data providers for invalid results.
|
||||
|
@ -41,9 +41,9 @@ abstract class RuleTestCase extends TestCase
|
|||
* as the first element and an input in which the validation SHOULD NOT pass.
|
||||
*
|
||||
* @api
|
||||
* @return array<string|int, array{Validatable, mixed}>
|
||||
* @return iterable<string|int, array{Validatable, mixed}>
|
||||
*/
|
||||
abstract public static function providerForInvalidInput(): array;
|
||||
abstract public static function providerForInvalidInput(): iterable;
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('providerForValidInput')]
|
||||
|
|
|
@ -18,25 +18,21 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
#[CoversClass(AllOf::class)]
|
||||
final class AllOfTest extends RuleTestCase
|
||||
{
|
||||
/** @return array<array{AllOf, mixed}> */
|
||||
public static function providerForValidInput(): array
|
||||
/** @return iterable<string, array{AllOf, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'pass' => [new AllOf(Stub::pass(1)), []],
|
||||
'pass, pass' => [new AllOf(Stub::pass(1), Stub::pass(1)), []],
|
||||
];
|
||||
yield 'pass' => [new AllOf(Stub::pass(1)), []];
|
||||
yield 'pass, pass' => [new AllOf(Stub::pass(1), Stub::pass(1)), []];
|
||||
}
|
||||
|
||||
/** @return array<array{AllOf, mixed}> */
|
||||
public static function providerForInvalidInput(): array
|
||||
/** @return iterable<string, array{AllOf, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'fail' => [new AllOf(Stub::fail(1)), []],
|
||||
'pass, fail' => [new AllOf(Stub::pass(1), Stub::fail(1)), []],
|
||||
'fail, pass' => [new AllOf(Stub::fail(1), Stub::pass(1)), []],
|
||||
'pass, pass, fail' => [new AllOf(Stub::pass(1), Stub::pass(1), Stub::fail(1)), []],
|
||||
'pass, fail, pass' => [new AllOf(Stub::pass(1), Stub::fail(1), Stub::pass(1)), []],
|
||||
'fail, pass, pass' => [new AllOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []],
|
||||
];
|
||||
yield 'fail' => [new AllOf(Stub::fail(1)), []];
|
||||
yield 'pass, fail' => [new AllOf(Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'fail, pass' => [new AllOf(Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'pass, pass, fail' => [new AllOf(Stub::pass(1), Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'pass, fail, pass' => [new AllOf(Stub::pass(1), Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'fail, pass, pass' => [new AllOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ final class AlnumTest extends RuleTestCase
|
|||
/**
|
||||
* @return array<array{Alnum, mixed}>
|
||||
*/
|
||||
public static function providerForValidInput(): array
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Alnum(), 'alganet'],
|
||||
|
@ -45,7 +45,7 @@ final class AlnumTest extends RuleTestCase
|
|||
/**
|
||||
* @return array<array{Alnum, mixed}>
|
||||
*/
|
||||
public static function providerForInvalidInput(): array
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Alnum(), ''],
|
||||
|
|
|
@ -18,24 +18,20 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
#[CoversClass(AnyOf::class)]
|
||||
final class AnyOfTest extends RuleTestCase
|
||||
{
|
||||
/** @return array<array{AnyOf, mixed}> */
|
||||
public static function providerForValidInput(): array
|
||||
/** @return iterable<string, array{AnyOf, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'pass' => [new AnyOf(Stub::pass(1)), []],
|
||||
'fail, pass' => [new AnyOf(Stub::fail(1), Stub::pass(1)), []],
|
||||
'fail, fail, pass' => [new AnyOf(Stub::fail(1), Stub::fail(1), Stub::pass(1)), []],
|
||||
'fail, pass, fail' => [new AnyOf(Stub::fail(1), Stub::pass(1), Stub::fail(1)), []],
|
||||
];
|
||||
yield 'pass' => [new AnyOf(Stub::pass(1)), []];
|
||||
yield 'fail, pass' => [new AnyOf(Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'fail, fail, pass' => [new AnyOf(Stub::fail(1), Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'fail, pass, fail' => [new AnyOf(Stub::fail(1), Stub::pass(1), Stub::fail(1)), []];
|
||||
}
|
||||
|
||||
/** @return array<array{AnyOf, mixed}> */
|
||||
public static function providerForInvalidInput(): array
|
||||
/** @return iterable<string, array{AnyOf, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'fail' => [new AnyOf(Stub::fail(1)), []],
|
||||
'fail, fail' => [new AnyOf(Stub::fail(1), Stub::fail(1)), []],
|
||||
'fail, fail, fail' => [new AnyOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []],
|
||||
];
|
||||
yield 'fail' => [new AnyOf(Stub::fail(1)), []];
|
||||
yield 'fail, fail' => [new AnyOf(Stub::fail(1), Stub::fail(1)), []];
|
||||
yield 'fail, fail, fail' => [new AnyOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
final class GraphTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return array<array{Graph, mixed}>
|
||||
*/
|
||||
public static function providerForValidInput(): array
|
||||
{
|
||||
|
|
|
@ -18,26 +18,22 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
#[CoversClass(NoneOf::class)]
|
||||
final class NoneOfTest extends RuleTestCase
|
||||
{
|
||||
/** @return array<array{NoneOf, mixed}> */
|
||||
public static function providerForValidInput(): array
|
||||
/** @return iterable<string, array{NoneOf, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'fail' => [new NoneOf(Stub::fail(1)), []],
|
||||
'fail, fail' => [new NoneOf(Stub::fail(1), Stub::fail(1)), []],
|
||||
'fail, fail, fail' => [new NoneOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []],
|
||||
];
|
||||
yield 'fail' => [new NoneOf(Stub::fail(1)), []];
|
||||
yield 'fail, fail' => [new NoneOf(Stub::fail(1), Stub::fail(1)), []];
|
||||
yield 'fail, fail, fail' => [new NoneOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []];
|
||||
}
|
||||
|
||||
/** @return array<array{NoneOf, mixed}> */
|
||||
public static function providerForInvalidInput(): array
|
||||
/** @return iterable<string, array{NoneOf, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'pass' => [new NoneOf(Stub::pass(1)), []],
|
||||
'pass, fail' => [new NoneOf(Stub::pass(1), Stub::fail(1)), []],
|
||||
'fail, pass' => [new NoneOf(Stub::fail(1), Stub::pass(1)), []],
|
||||
'pass, pass, fail' => [new NoneOf(Stub::pass(1), Stub::pass(1), Stub::fail(1)), []],
|
||||
'pass, fail, pass' => [new NoneOf(Stub::pass(1), Stub::fail(1), Stub::pass(1)), []],
|
||||
'fail, pass, pass' => [new NoneOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []],
|
||||
];
|
||||
yield 'pass' => [new NoneOf(Stub::pass(1)), []];
|
||||
yield 'pass, fail' => [new NoneOf(Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'fail, pass' => [new NoneOf(Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'pass, pass, fail' => [new NoneOf(Stub::pass(1), Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'pass, fail, pass' => [new NoneOf(Stub::pass(1), Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'fail, pass, pass' => [new NoneOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,27 +18,23 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
#[CoversClass(OneOf::class)]
|
||||
final class OneOfTest extends RuleTestCase
|
||||
{
|
||||
/** @return array<array{OneOf, mixed}> */
|
||||
public static function providerForValidInput(): array
|
||||
/** @return iterable<string, array{OneOf, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'pass' => [new OneOf(Stub::pass(1)), []],
|
||||
'fail, pass' => [new OneOf(Stub::fail(1), Stub::pass(1)), []],
|
||||
'pass, fail' => [new OneOf(Stub::pass(1), Stub::fail(1)), []],
|
||||
'pass, fail, fail' => [new OneOf(Stub::pass(1), Stub::fail(1), Stub::fail(1)), []],
|
||||
'fail, pass, fail' => [new OneOf(Stub::fail(1), Stub::pass(1), Stub::fail(1)), []],
|
||||
'fail, fail, pass' => [new OneOf(Stub::fail(1), Stub::fail(1), Stub::pass(1)), []],
|
||||
];
|
||||
yield 'pass' => [new OneOf(Stub::pass(1)), []];
|
||||
yield 'fail, pass' => [new OneOf(Stub::fail(1), Stub::pass(1)), []];
|
||||
yield 'pass, fail' => [new OneOf(Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'pass, fail, fail' => [new OneOf(Stub::pass(1), Stub::fail(1), Stub::fail(1)), []];
|
||||
yield 'fail, pass, fail' => [new OneOf(Stub::fail(1), Stub::pass(1), Stub::fail(1)), []];
|
||||
yield 'fail, fail, pass' => [new OneOf(Stub::fail(1), Stub::fail(1), Stub::pass(1)), []];
|
||||
}
|
||||
|
||||
/** @return array<array{OneOf, mixed}> */
|
||||
public static function providerForInvalidInput(): array
|
||||
/** @return iterable<string, array{OneOf, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
'fail' => [new OneOf(Stub::fail(1)), []],
|
||||
'fail, fail' => [new OneOf(Stub::fail(1), Stub::fail(1)), []],
|
||||
'fail, fail, fail' => [new OneOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []],
|
||||
'fail, pass, pass' => [new OneOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []],
|
||||
];
|
||||
yield 'fail' => [new OneOf(Stub::fail(1)), []];
|
||||
yield 'fail, fail' => [new OneOf(Stub::fail(1), Stub::fail(1)), []];
|
||||
yield 'fail, fail, fail' => [new OneOf(Stub::fail(1), Stub::fail(1), Stub::fail(1)), []];
|
||||
yield 'fail, pass, pass' => [new OneOf(Stub::fail(1), Stub::pass(1), Stub::pass(1)), []];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue