@@ -36,17 +36,17 @@ private function getService(): ValidateService {
36
36
public function testValidateWithValidInput (string $ fieldName , string $ value ): void {
37
37
$ service = $ this ->getService ();
38
38
$ service ->validate ($ fieldName , $ value );
39
- $ this ->assertTrue (true ); // se não lançar exceção, passou
39
+ $ this ->assertTrue (true );
40
40
}
41
41
42
42
public static function providerValidInputs (): array {
43
43
return [
44
- ['CN ' , 'John Doe ' ], // requerido, dentro do limite
45
- ['C ' , 'BR ' ], // exatamente 2 letras
46
- ['ST ' , 'Amazonas ' ], // válido
47
- ['L ' , 'Manaus ' ], // válido
48
- ['O ' , 'LibreCode ' ], // válido
49
- ['OU ' , 'Development ' ], // válido
44
+ ['CN ' , 'John Doe ' ],
45
+ ['C ' , 'BR ' ],
46
+ ['ST ' , 'Amazonas ' ],
47
+ ['L ' , 'Manaus ' ],
48
+ ['O ' , 'LibreCode ' ],
49
+ ['OU ' , 'Development ' ],
50
50
];
51
51
}
52
52
@@ -60,16 +60,11 @@ public function testValidateWithInvalidInput(string $fieldName, string $value, s
60
60
61
61
public static function providerInvalidInputs (): array {
62
62
return [
63
- // CN é obrigatório → vazio deve falhar
64
63
['CN ' , '' , "Parameter 'CN' is required! " ],
65
- // CN muito longo
66
- ['CN ' , str_repeat ('a ' , 65 ), "Parameter 'CN' should be betweeen 1 and 64. " ],
67
- // C muito curto
68
- ['C ' , 'B ' , "Parameter 'C' should be betweeen 2 and 2. " ],
69
- // C muito longo
70
- ['C ' , 'BRA ' , "Parameter 'C' should be betweeen 2 and 2. " ],
71
- // ST acima do limite
72
- ['ST ' , str_repeat ('x ' , 129 ), "Parameter 'ST' should be betweeen 1 and 128. " ],
64
+ ['CN ' , str_repeat ('a ' , 65 ), "Parameter 'CN' should be between 1 and 64. " ],
65
+ ['C ' , 'B ' , "Parameter 'C' should be between 2 and 2. " ],
66
+ ['C ' , 'BRA ' , "Parameter 'C' should be between 2 and 2. " ],
67
+ ['ST ' , str_repeat ('x ' , 129 ), "Parameter 'ST' should be between 1 and 128. " ],
73
68
];
74
69
}
75
70
@@ -90,7 +85,8 @@ public function testValidateNamesWithoutIdShouldFail(): void {
90
85
$ service = $ this ->getService ();
91
86
92
87
$ names = [
93
- ['id ' => '' , 'value ' => 'Invalid Name ' ],
88
+ ['id ' => '' , 'value ' => 'Name ' ],
89
+ ['value ' => 'Name ' ],
94
90
];
95
91
96
92
$ this ->expectException (InvalidArgumentException::class);
@@ -99,16 +95,23 @@ public function testValidateNamesWithoutIdShouldFail(): void {
99
95
$ service ->validateNames ($ names );
100
96
}
101
97
102
- public function testValidateNamesWithInvalidValueShouldFail (): void {
103
- $ service = $ this ->getService ();
104
98
105
- $ names = [
106
- [ ' id ' => ' C ' , ' value ' => ' BRA ' ], // inválido, deve ter 2 chars
107
- ] ;
99
+ #[DataProvider( ' providerInvalidNames ' )]
100
+ public function testValidateNamesWithInvalidValueShouldFail ( array $ name , string $ expectedMessage ): void {
101
+ $ service = $ this -> getService () ;
108
102
109
103
$ this ->expectException (InvalidArgumentException::class);
110
- $ this ->expectExceptionMessage (" Parameter 'C' should be betweeen 2 and 2. " );
104
+ $ this ->expectExceptionMessage ($ expectedMessage );
111
105
112
- $ service ->validateNames ($ names );
106
+ $ service ->validateNames ([$ name ]);
107
+ }
108
+
109
+ public static function providerInvalidNames (): array {
110
+ return [
111
+ [['id ' => 'C ' , 'value ' => '' ], "Parameter 'C' should be between 2 and 2. " ],
112
+ [['id ' => 'C ' , 'value ' => 'B ' ], "Parameter 'C' should be between 2 and 2. " ],
113
+ [['id ' => 'C ' , 'value ' => 'BRA ' ], "Parameter 'C' should be between 2 and 2. " ],
114
+ [['id ' => 'C ' , 'value ' => 'BRAA ' ], "Parameter 'C' should be between 2 and 2. " ],
115
+ ];
113
116
}
114
117
}
0 commit comments