Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 77a0145

Browse files
committed
tests: improved unexpected messages
1 parent 9ce86d0 commit 77a0145

15 files changed

+98
-76
lines changed

tests/ChoiceTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ class ChoiceTest extends AbstractTest
1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
2121
$constraints = [1, 2, 3, 4, 5];
22-
$multipleMessage = '/Expected value of type "array", "(.*)" given/';
23-
$constraintMessage = '/Maximum value must be greater than or equal to minimum value./';
2422

25-
yield 'multiple not array' => [new Choice($constraints, true), 1, $multipleMessage];
26-
yield 'min greater than max constraint' => [new Choice($constraints, true, 3, 2), [1, 2], $constraintMessage];
23+
$unexpectedMultipleMessage = '/Expected value of type "array", "(.*)" given/';
24+
$unexpectedMinMaxMessage = '/Maximum value must be greater than or equal to minimum value./';
25+
26+
yield 'multiple not array' => [new Choice($constraints, true), 1, $unexpectedMultipleMessage];
27+
yield 'min greater than max constraint' => [new Choice($constraints, true, 3, 2), [1, 2], $unexpectedMinMaxMessage];
2728
}
2829

2930
public static function provideRuleFailureConditionData(): \Generator
3031
{
3132
$constraints = [1, 2, 3, 4, 5];
3233
$exception = ChoiceException::class;
34+
3335
$message = '/The (.*) value is not a valid choice, (.*) given. Accepted values are: (.*)./';
3436
$multipleMessage = '/The (.*) value has one or more invalid choices, (.*) given. Accepted values are: (.*)./';
3537
$maxMessage = '/The (.*) value must have at most (.*) choices, (.*) choices given./';

tests/CountTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ class CountTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$missingOptionsMessage = '/At least one of the options "min" or "max" must be given./';
22-
$invalidTypeMessage = '/Expected value of type "array|\Countable", "(.*)" given./';
23-
$constraintMessage = '/Maximum value must be greater than or equal to minimum value./';
21+
$unexpectedOptionMessage = '/At least one of the options "min" or "max" must be given./';
22+
$unexpectedTypeMessage = '/Expected value of type "array|\Countable", "(.*)" given./';
23+
$unexpectedMinMaxMessage = '/Maximum value must be greater than or equal to minimum value./';
2424

25-
yield 'missing options' => [new Count(), [1, 2, 3], $missingOptionsMessage];
26-
yield 'invalid type value' => [new Count(min: 5, max: 10), 1, $invalidTypeMessage];
27-
yield 'min greater than max constraint' => [new Count(min: 10, max: 5), 1, $constraintMessage];
25+
yield 'missing options' => [new Count(), [1, 2, 3], $unexpectedOptionMessage];
26+
yield 'invalid type value' => [new Count(min: 5, max: 10), 1, $unexpectedTypeMessage];
27+
yield 'min greater than max constraint' => [new Count(min: 3, max: 2), [1, 2, 3], $unexpectedMinMaxMessage];
2828
}
2929

3030
public static function provideRuleFailureConditionData(): \Generator
3131
{
3232
$value = [1, 2, 3, 4, 5];
3333
$exception = CountException::class;
34+
3435
$minMessage = '/The (.*) value should contain (.*) elements or more, (.*) elements given./';
3536
$maxMessage = '/The (.*) value should contain (.*) elements or less, (.*) elements given./';
3637
$exactMessage = '/The (.*) value should contain exactly (.*) elements, (.*) elements given./';

tests/CountryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class CountryTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$codeMessage = '/Invalid code "(.*)". Accepted values are: "(.*)"./';
22-
$typeMessage = '/Expected value of type "string", (.*) given./';
21+
$unexpectedCodeMessage = '/Invalid code "(.*)". Accepted values are: "(.*)"./';
22+
$unexpectedTypeMessage = '/Expected value of type "string", (.*) given./';
2323

24-
yield 'invalid code' => [new Country('invalid'), 'PT', $codeMessage];
25-
yield 'invalid type' => [new Country(), 123, $typeMessage];
24+
yield 'invalid code' => [new Country('invalid'), 'PT', $unexpectedCodeMessage];
25+
yield 'invalid type' => [new Country(), 123, $unexpectedTypeMessage];
2626
}
2727

2828
public static function provideRuleFailureConditionData(): \Generator

tests/EachKeyTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ class EachKeyTest extends AbstractTest
2121

2222
public static function provideRuleUnexpectedValueData(): \Generator
2323
{
24+
$unexpectedTypeMessage = '/Expected value of type "(.*)", "(.*)" given./';
25+
$unexpectedPropagationMessage = '/Cannot compare a type "(.*)" with a type "(.*)"./';
26+
2427
yield 'invalid value type' => [
2528
new EachKey(new Validator(new Type('string'))),
2629
'invalid',
27-
'/Expected value of type "(.*)", "(.*)" given./'
30+
$unexpectedTypeMessage
2831
];
2932
yield 'unexpected value propagation' => [
3033
new EachKey(new Validator(new GreaterThan(10))),
3134
['key1' => 1],
32-
'/Cannot compare a type "(.*)" with a type "(.*)"./'
35+
$unexpectedPropagationMessage
3336
];
3437
}
3538

tests/EachValueTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ class EachValueTest extends AbstractTest
2121

2222
public static function provideRuleUnexpectedValueData(): \Generator
2323
{
24+
$unexpectedTypeMessage = '/Expected value of type "(.*)", "(.*)" given./';
25+
$unexpectedPropagationMessage = '/Cannot compare a type "(.*)" with a type "(.*)"./';
26+
2427
yield 'invalid value type' => [
2528
new EachValue(new Validator(new NotBlank())),
2629
'invalid',
27-
'/Expected value of type "(.*)", "(.*)" given./'
30+
$unexpectedTypeMessage
2831
];
2932
yield 'unexpected value propagation' => [
3033
new EachValue(new Validator(new GreaterThan(10))),
3134
['a'],
32-
'/Cannot compare a type "(.*)" with a type "(.*)"./'
35+
$unexpectedPropagationMessage
3336
];
3437
}
3538

tests/EmailTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class EmailTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$optionMessage = '/Invalid (.*) "(.*)". Accepted values are: "(.*)"./';
22-
$typeMessage = '/Expected value of type "string", "(.*)" given./';
21+
$unexpectedOptionMessage = '/Invalid (.*) "(.*)". Accepted values are: "(.*)"./';
22+
$unexpectedTypeMessage = '/Expected value of type "string", "(.*)" given./';
2323

24-
yield 'invalid option' => [new Email('invalid'), 'test@example.com', $optionMessage];
25-
yield 'invalid type' => [new Email(), 1, $typeMessage];
24+
yield 'invalid option' => [new Email('invalid'), 'test@example.com', $unexpectedOptionMessage];
25+
yield 'invalid type' => [new Email(), 1, $unexpectedTypeMessage];
2626
}
2727

2828
public static function provideRuleFailureConditionData(): \Generator

tests/GreaterThanOrEqualTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class GreaterThanOrEqualTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$message = '/Cannot compare a type "(.*)" with a type "(.*)"/';
21+
$unexpectedTypeMessage = '/Cannot compare a type "(.*)" with a type "(.*)"/';
2222

23-
yield 'datetime constraint with int value' => [new GreaterThanOrEqual(new \DateTime()), 10, $message];
24-
yield 'datetime constraint with float value' => [new GreaterThanOrEqual(new \DateTime()), 1.0, $message];
25-
yield 'datetime constraint with string value' => [new GreaterThanOrEqual(new \DateTime()), 'a', $message];
26-
yield 'int constraint with string value' => [new GreaterThanOrEqual(10), 'a', $message];
27-
yield 'float constraint with string value' => [new GreaterThanOrEqual(1.0), 'a', $message];
28-
yield 'array constraint' => [new GreaterThanOrEqual([10]), 10, $message];
29-
yield 'null constraint' => [new GreaterThanOrEqual(null), 10, $message];
23+
yield 'datetime constraint with int value' => [new GreaterThanOrEqual(new \DateTime()), 10, $unexpectedTypeMessage];
24+
yield 'datetime constraint with float value' => [new GreaterThanOrEqual(new \DateTime()), 1.0, $unexpectedTypeMessage];
25+
yield 'datetime constraint with string value' => [new GreaterThanOrEqual(new \DateTime()), 'a', $unexpectedTypeMessage];
26+
yield 'int constraint with string value' => [new GreaterThanOrEqual(10), 'a', $unexpectedTypeMessage];
27+
yield 'float constraint with string value' => [new GreaterThanOrEqual(1.0), 'a', $unexpectedTypeMessage];
28+
yield 'array constraint' => [new GreaterThanOrEqual([10]), 10, $unexpectedTypeMessage];
29+
yield 'null constraint' => [new GreaterThanOrEqual(null), 10, $unexpectedTypeMessage];
3030
}
3131

3232
public static function provideRuleFailureConditionData(): \Generator

tests/GreaterThanTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class GreaterThanTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$message = '/Cannot compare a type "(.*)" with a type "(.*)"/';
21+
$unexpectedTypeMessage = '/Cannot compare a type "(.*)" with a type "(.*)"/';
2222

23-
yield 'datetime constraint with int value' => [new GreaterThan(new \DateTime()), 10, $message];
24-
yield 'datetime constraint with float value' => [new GreaterThan(new \DateTime()), 1.0, $message];
25-
yield 'datetime constraint with string value' => [new GreaterThan(new \DateTime()), 'a', $message];
26-
yield 'int constraint with string value' => [new GreaterThan(10), 'a', $message];
27-
yield 'float constraint with string value' => [new GreaterThan(1.0), 'a', $message];
28-
yield 'array constraint' => [new GreaterThan([10]), 10, $message];
29-
yield 'null constraint' => [new GreaterThan(null), 10, $message];
23+
yield 'datetime constraint with int value' => [new GreaterThan(new \DateTime()), 10, $unexpectedTypeMessage];
24+
yield 'datetime constraint with float value' => [new GreaterThan(new \DateTime()), 1.0, $unexpectedTypeMessage];
25+
yield 'datetime constraint with string value' => [new GreaterThan(new \DateTime()), 'a', $unexpectedTypeMessage];
26+
yield 'int constraint with string value' => [new GreaterThan(10), 'a', $unexpectedTypeMessage];
27+
yield 'float constraint with string value' => [new GreaterThan(1.0), 'a', $unexpectedTypeMessage];
28+
yield 'array constraint' => [new GreaterThan([10]), 10, $unexpectedTypeMessage];
29+
yield 'null constraint' => [new GreaterThan(null), 10, $unexpectedTypeMessage];
3030
}
3131

3232
public static function provideRuleFailureConditionData(): \Generator

tests/LessThanOrEqualTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class LessThanOrEqualTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$message = '/Cannot compare a type "(.*)" with a type "(.*)"/';
21+
$unexpectedTypeMessage = '/Cannot compare a type "(.*)" with a type "(.*)"/';
2222

23-
yield 'datetime constraint with int value' => [new LessThanOrEqual(new \DateTime()), 10, $message];
24-
yield 'datetime constraint with float value' => [new LessThanOrEqual(new \DateTime()), 1.0, $message];
25-
yield 'datetime constraint with string value' => [new LessThanOrEqual(new \DateTime()), 'a', $message];
26-
yield 'int constraint with string value' => [new LessThanOrEqual(10), 'a', $message];
27-
yield 'float constraint with string value' => [new LessThanOrEqual(1.0), 'a', $message];
28-
yield 'array constraint' => [new LessThanOrEqual([10]), 10, $message];
29-
yield 'null constraint' => [new LessThanOrEqual(null), 10, $message];
23+
yield 'datetime constraint with int value' => [new LessThanOrEqual(new \DateTime()), 10, $unexpectedTypeMessage];
24+
yield 'datetime constraint with float value' => [new LessThanOrEqual(new \DateTime()), 1.0, $unexpectedTypeMessage];
25+
yield 'datetime constraint with string value' => [new LessThanOrEqual(new \DateTime()), 'a', $unexpectedTypeMessage];
26+
yield 'int constraint with string value' => [new LessThanOrEqual(10), 'a', $unexpectedTypeMessage];
27+
yield 'float constraint with string value' => [new LessThanOrEqual(1.0), 'a', $unexpectedTypeMessage];
28+
yield 'array constraint' => [new LessThanOrEqual([10]), 10, $unexpectedTypeMessage];
29+
yield 'null constraint' => [new LessThanOrEqual(null), 10, $unexpectedTypeMessage];
3030
}
3131

3232
public static function provideRuleFailureConditionData(): \Generator

tests/LessThanTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class LessThanTest extends AbstractTest
1818

1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
21-
$message = '/Cannot compare a type "(.*)" with a type "(.*)"/';
21+
$unexpectedTypeMessage = '/Cannot compare a type "(.*)" with a type "(.*)"/';
2222

23-
yield 'datetime constraint with int value' => [new LessThan(new \DateTime()), 10, $message];
24-
yield 'datetime constraint with float value' => [new LessThan(new \DateTime()), 1.0, $message];
25-
yield 'datetime constraint with string value' => [new LessThan(new \DateTime()), 'a', $message];
26-
yield 'int constraint with string value' => [new LessThan(10), 'a', $message];
27-
yield 'float constraint with string value' => [new LessThan(1.0), 'a', $message];
28-
yield 'array constraint' => [new LessThan([10]), 10, $message];
29-
yield 'null constraint' => [new LessThan(null), 10, $message];
23+
yield 'datetime constraint with int value' => [new LessThan(new \DateTime()), 10, $unexpectedTypeMessage];
24+
yield 'datetime constraint with float value' => [new LessThan(new \DateTime()), 1.0, $unexpectedTypeMessage];
25+
yield 'datetime constraint with string value' => [new LessThan(new \DateTime()), 'a', $unexpectedTypeMessage];
26+
yield 'int constraint with string value' => [new LessThan(10), 'a', $unexpectedTypeMessage];
27+
yield 'float constraint with string value' => [new LessThan(1.0), 'a', $unexpectedTypeMessage];
28+
yield 'array constraint' => [new LessThan([10]), 10, $unexpectedTypeMessage];
29+
yield 'null constraint' => [new LessThan(null), 10, $unexpectedTypeMessage];
3030
}
3131

3232
public static function provideRuleFailureConditionData(): \Generator

0 commit comments

Comments
 (0)