@@ -36,17 +36,17 @@ private function getService(): ValidateService {
3636 public function testValidateWithValidInput (string $ fieldName , string $ value ): void {
3737 $ service = $ this ->getService ();
3838 $ service ->validate ($ fieldName , $ value );
39- $ this ->assertTrue (true ); // se não lançar exceção, passou
39+ $ this ->assertTrue (true );
4040 }
4141
4242 public static function providerValidInputs (): array {
4343 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 ' ],
5050 ];
5151 }
5252
@@ -60,16 +60,11 @@ public function testValidateWithInvalidInput(string $fieldName, string $value, s
6060
6161 public static function providerInvalidInputs (): array {
6262 return [
63- // CN é obrigatório → vazio deve falhar
6463 ['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. " ],
7368 ];
7469 }
7570
@@ -90,7 +85,8 @@ public function testValidateNamesWithoutIdShouldFail(): void {
9085 $ service = $ this ->getService ();
9186
9287 $ names = [
93- ['id ' => '' , 'value ' => 'Invalid Name ' ],
88+ ['id ' => '' , 'value ' => 'Name ' ],
89+ ['value ' => 'Name ' ],
9490 ];
9591
9692 $ this ->expectException (InvalidArgumentException::class);
@@ -99,16 +95,23 @@ public function testValidateNamesWithoutIdShouldFail(): void {
9995 $ service ->validateNames ($ names );
10096 }
10197
102- public function testValidateNamesWithInvalidValueShouldFail (): void {
103- $ service = $ this ->getService ();
10498
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 () ;
108102
109103 $ this ->expectException (InvalidArgumentException::class);
110- $ this ->expectExceptionMessage (" Parameter 'C' should be betweeen 2 and 2. " );
104+ $ this ->expectExceptionMessage ($ expectedMessage );
111105
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+ ];
113116 }
114117}
0 commit comments