Skip to content

Commit f2d0aa3

Browse files
committed
fix a few more errors
1 parent e84f9b4 commit f2d0aa3

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

src/Validator/Choice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public function __construct(
1717
/**
1818
* @throws \UnexpectedValueException
1919
*/
20-
public function __invoke(mixed $value): string|int|float {
20+
public function __invoke(mixed $value): ?string {
2121
return match(FALSE) {
2222
\is_string($value) || \is_int($value) || \is_float($value),
23-
\in_array($value, $this->choices, TRUE) => throw new \UnexpectedValueException($this->message),
24-
default => $value,
23+
\in_array($value, $this->choices, TRUE) => $this->message,
24+
default => NULL,
2525
};
2626
}
2727

tests/unit/Validator/MachineNameTest.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,27 @@ final class MachineNameTest extends TestCase {
1717
* Test callback.
1818
*/
1919
#[DataProvider('dataProvider')]
20-
public function test(mixed $machine_name, ?\UnexpectedValueException $exception): void {
21-
if ($exception) {
22-
$this->expectExceptionObject($exception);
23-
}
24-
self::assertSame($machine_name, (new MachineName())($machine_name));
20+
public function test(mixed $machine_name, ?string $expected): void {
21+
self::assertSame($expected, (new MachineName())($machine_name));
2522
}
2623

2724
public static function dataProvider(): array {
28-
$exception = new \UnexpectedValueException('The value is not correct machine name.');
25+
$error = 'The value is not correct machine name.';
2926
return [
3027
['snake_case_here', NULL],
3128
['ends_with_number123', NULL],
32-
['UPPER_CASE', $exception],
33-
['123begins_with_number', $exception],
34-
['with.dot', $exception],
35-
[' not_trimmed ', $exception],
36-
['Hello world ', $exception],
37-
['ends_with_underscore_', $exception],
38-
['', $exception],
39-
['foo*&)(*&@#()*&@#bar', $exception],
40-
[TRUE, $exception],
41-
[NULL, $exception],
42-
[[], $exception],
43-
[new \stdClass(), $exception],
29+
['UPPER_CASE', $error],
30+
['123begins_with_number', $error],
31+
['with.dot', $error],
32+
[' not_trimmed ', $error],
33+
['Hello world ', $error],
34+
['ends_with_underscore_', $error],
35+
['', $error],
36+
['foo*&)(*&@#()*&@#bar', $error],
37+
[TRUE, $error],
38+
[NULL, $error],
39+
[[], $error],
40+
[new \stdClass(), $error],
4441
];
4542
}
4643

tests/unit/Validator/OptionalTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@ final class OptionalTest extends TestCase {
1818
* Test callback.
1919
*/
2020
#[DataProvider('dataProvider')]
21-
public function test(mixed $machine_name, ?\UnexpectedValueException $exception): void {
22-
if ($exception) {
23-
$this->expectExceptionObject($exception);
24-
}
21+
public function test(mixed $machine_name, ?string $expected): void {
2522
$validator = new Optional(new MachineName());
26-
self::assertSame($machine_name, $validator($machine_name));
23+
self::assertSame($expected, $validator($machine_name));
2724
}
2825

2926
public static function dataProvider(): array {
30-
$exception = new \UnexpectedValueException('The value is not correct machine name.');
27+
$error = 'The value is not correct machine name.';
3128
return [
32-
['foo*&)(*&@#()*&@#bar', $exception],
33-
[TRUE, $exception],
29+
['foo*&)(*&@#()*&@#bar', $error],
30+
[TRUE, $error],
3431
[NULL, NULL],
3532
['', NULL],
36-
[' ', $exception],
37-
[new \stdClass(), $exception],
33+
[' ', $error],
34+
[new \stdClass(), $error],
3835
];
3936
}
4037

0 commit comments

Comments
 (0)