Skip to content

Commit e84f9b4

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

File tree

6 files changed

+40
-52
lines changed

6 files changed

+40
-52
lines changed

src/Validator/RequiredMachineName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class RequiredMachineName {
1111

1212
/**
13-
* @throws \UnexpectedValueException
13+
* Magic method.
1414
*/
1515
public function __invoke(mixed $value): ?string {
1616
return (new Chained(new Required(), new MachineName()))($value);

src/Validator/ServiceName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class ServiceName {
1111

1212
/**
13-
* @throws \UnexpectedValueException
13+
* Magic method.
1414
*/
1515
public function __invoke(mixed $value): ?string {
1616
if (!\is_string($value) || !\preg_match('/^[a-z][a-z0-9_\.]*[a-z0-9]$/', $value)) {

tests/unit/Validator/ChoiceTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@ final class ChoiceTest extends TestCase {
1717
* Test callback.
1818
*/
1919
#[DataProvider('dataProvider')]
20-
public function test(mixed $value, array $choices, ?string $message, ?\UnexpectedValueException $exception): void {
20+
public function test(mixed $value, array $choices, ?string $message, ?string $expected): void {
2121
$validator = $message ? new Choice($choices, $message) : new Choice($choices);
22-
if ($exception) {
23-
$this->expectExceptionObject($exception);
24-
}
25-
self::assertSame($value, $validator($value));
22+
self::assertSame($expected, $validator($value));
2623
}
2724

2825
public static function dataProvider(): array {
29-
$default_exception = new \UnexpectedValueException('The value you selected is not a valid choice.');
26+
$default_error = 'The value you selected is not a valid choice.';
3027
return [
31-
['wrong', ['aaa', 'bbb'], NULL, $default_exception],
28+
['wrong', ['aaa', 'bbb'], NULL, $default_error],
3229
['aaa', ['aaa', 'bbb'], NULL, NULL],
33-
['wrong', ['aaa', 'bbb'], 'Custom message.', new \UnexpectedValueException('Custom message.')],
34-
[111, ['111', '222'], NULL, $default_exception],
35-
['111', [111, 222], NULL, $default_exception],
30+
['wrong', ['aaa', 'bbb'], 'Custom message.', 'Custom message.'],
31+
[111, ['111', '222'], NULL, $default_error],
32+
['111', [111, 222], NULL, $default_error],
3633
[111, [111, 222], NULL, NULL],
37-
[FALSE, ['aaa', 'bbb'], NULL, $default_exception],
38-
[[], ['aaa', 'bbb'], NULL, $default_exception],
34+
[FALSE, ['aaa', 'bbb'], NULL, $default_error],
35+
[[], ['aaa', 'bbb'], NULL, $default_error],
3936
];
4037
}
4138

tests/unit/Validator/RequiredMachineNameTest.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@ final class RequiredMachineNameTest 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 RequiredMachineName())($machine_name));
20+
public function test(mixed $machine_name, $expected): void {
21+
self::assertSame($expected, (new RequiredMachineName())($machine_name));
2522
}
2623

2724
public static function dataProvider(): array {
28-
$mn_exception = new \UnexpectedValueException('The value is not correct machine name.');
29-
$rq_exception = new \UnexpectedValueException('The value is required.');
25+
$mn_error = 'The value is not correct machine name.';
26+
$rq_error = 'The value is required.';
3027
return [
3128
['snake_case_here', NULL],
3229
['ends_with_number123', NULL],
33-
['UPPER_CASE', $mn_exception],
34-
['123begins_with_number', $mn_exception],
35-
['0', $mn_exception],
36-
['', $rq_exception],
37-
[NULL, $rq_exception],
38-
[FALSE, $mn_exception],
39-
[TRUE, $mn_exception],
30+
['UPPER_CASE', $mn_error],
31+
['123begins_with_number', $mn_error],
32+
['0', $mn_error],
33+
['', $rq_error],
34+
[NULL, $rq_error],
35+
[FALSE, $mn_error],
36+
[TRUE, $mn_error],
4037
];
4138
}
4239

tests/unit/Validator/RequiredTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,20 @@ final class RequiredTest 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 Required())($machine_name));
20+
public function test(mixed $machine_name, ?string $expected): void {
21+
self::assertSame($expected, (new Required())($machine_name));
2522
}
2623

2724
public static function dataProvider(): array {
28-
$exception = new \UnexpectedValueException('The value is required.');
25+
$error = 'The value is required.';
2926
return [
3027
['yes', NULL],
3128
['0', NULL],
32-
['', $exception],
33-
[NULL, $exception],
29+
['', $error],
30+
[NULL, $error],
3431
[FALSE, NULL],
3532
[TRUE, NULL],
36-
[[], $exception],
33+
[[], $error],
3734
[['foo'], NULL],
3835
];
3936
}

tests/unit/Validator/ServiceNameTest.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,24 @@ final class ServiceNameTest 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 ServiceName())($machine_name));
20+
public function test(mixed $machine_name, ?string $expected): void {
21+
self::assertSame($expected, (new ServiceName())($machine_name));
2522
}
2623

2724
public static function dataProvider(): array {
28-
$exception = new \UnexpectedValueException('The value is not correct service name.');
25+
$error = 'The value is not correct service name.';
2926
return [
3027
['snake_case_here', NULL],
3128
['dot.inside', NULL],
32-
['CamelCaseHere', $exception],
33-
[' not_trimmed ', $exception],
34-
['.leading.dot', $exception],
35-
['ending.dot.', $exception],
36-
['special&character', $exception],
37-
[TRUE, $exception],
38-
[NULL, $exception],
39-
[[], $exception],
40-
[new \stdClass(), $exception],
29+
['CamelCaseHere', $error],
30+
[' not_trimmed ', $error],
31+
['.leading.dot', $error],
32+
['ending.dot.', $error],
33+
['special&character', $error],
34+
[TRUE, $error],
35+
[NULL, $error],
36+
[[], $error],
37+
[new \stdClass(), $error],
4138
];
4239
}
4340

0 commit comments

Comments
 (0)