99use PHPUnit \Framework \Attributes \Test ;
1010use PHPUnit \Framework \TestCase ;
1111
12- class ValidatorsFactoryTest extends TestCase {
12+ class ValidatorsFactoryTest extends TestCase
13+ {
14+ public static function notValidInputProvider ()
15+ {
16+ return [
17+ [5 ],
18+ [true ],
19+ [5.09 ],
20+ [null ],
21+ ];
22+ }
1323
14- public static function notValidInputProvider () {
15- return [
16- [5 ],
17- [true ],
18- [5.09 ],
19- [null ],
20- ];
21- }
24+ #[Test]
25+ #[DataProvider('notValidInputProvider ' )]
26+ public function itThrowsAnErrorWhenTryToCreateValidatorWithInvalidData ($ input )
27+ {
28+ $ validatorFactory = new ValidatorsFactory ();
29+ $ this ->expectException (\InvalidArgumentException::class);
30+ $ this ->expectExceptionMessage ("Not valid input to create a validator " );
31+ $ validatorFactory ->create ($ input );
32+ }
2233
23- #[Test]
24- #[DataProvider('notValidInputProvider ' )]
25- public function itThrowsAnErrorWhenTryToCreateValidatorWithInvalidData ($ input ) {
26- $ validatorFactory = new ValidatorsFactory ();
27- $ this ->expectException (\InvalidArgumentException::class);
28- $ this ->expectExceptionMessage ("Not valid input to create a validator " );
29- $ validatorFactory ->create ($ input );
30- }
34+ #[Test]
35+ public function itValidatesAForm ()
36+ {
37+ $ validatorFactory = new ValidatorsFactory ();
38+ $ validator = $ validatorFactory ->create ([
39+ 'email ' => ['required ' , 'email ' ],
40+ 'password ' => ['required ' , 'max:16 ' ],
41+ ]);
42+ $ errors = $ validator ->validate ([
43+ 'email ' => 'user@example.com ' ,
44+ 'password ' => 'secret123 ' ,
45+ ]);
46+ $ this ->assertEmpty ($ errors );
47+ }
3148
32- #[Test]
33- public function itValidatesAForm () {
34- $ validatorFactory = new ValidatorsFactory ();
35- $ validator = $ validatorFactory ->create ([
36- 'email ' => ['required ' , 'email ' ],
37- 'password ' => ['required ' , 'max:16 ' ],
38- ]);
39- $ errors = $ validator ->validate ([
40- 'email ' => 'user@example.com ' ,
41- 'password ' => 'secret123 ' ,
42- ]);
43- $ this ->assertEmpty ($ errors );
44- }
49+ #[Test]
50+ public function itValidatesAField ()
51+ {
52+ $ validatorFactory = new ValidatorsFactory ();
53+ $ validator = $ validatorFactory ->create (['required ' , 'email ' ]);
54+ $ errors = $ validator ->validate ('user@example.com ' );
55+ $ this ->assertEmpty ($ errors );
56+ }
4557
46- #[Test]
47- public function itValidatesAField () {
48- $ validatorFactory = new ValidatorsFactory ();
49- $ validator = $ validatorFactory ->create (['required ' , 'email ' ]);
50- $ errors = $ validator ->validate ('user@example.com ' );
51- $ this ->assertEmpty ($ errors );
52- }
58+ #[Test]
59+ public function itDontValidatesAField ()
60+ {
61+ $ validatorFactory = new ValidatorsFactory ();
62+ $ validator = $ validatorFactory ->create (['required ' , 'url ' ]);
63+ $ errors = $ validator ->validate ('user@example.com ' );
64+ $ this ->assertNotEmpty ($ errors );
65+ $ this ->assertContains ('The input should be an url ' , $ errors );
66+ }
5367
54- #[Test]
55- public function itDontValidatesAField () {
56- $ validatorFactory = new ValidatorsFactory ();
57- $ validator = $ validatorFactory-> create ([ ' required ' , ' url ' ] );
58- $ errors = $ validator -> validate ( ' user@example.com ' );
59- $ this -> assertNotEmpty ( $ errors );
60- $ this ->assertContains ( ' The input should be an url ' , $ errors );
61- }
68+ #[Test]
69+ public function itValidatesAValueWithASingleRule ()
70+ {
71+ $ validatorFactory = new ValidatorsFactory ( );
72+ $ validator = $ validatorFactory -> create ( ' required ' );
73+ $ errors = $ validator -> validate ( ' something ' );
74+ $ this ->assertEmpty ( $ errors );
75+ }
6276
63- #[Test]
64- public function itValidatesAValueWithASingleRule () {
65- $ validatorFactory = new ValidatorsFactory ();
66- $ validator = $ validatorFactory ->create ('required ' );
67- $ errors = $ validator ->validate ('something ' );
68- $ this ->assertEmpty ($ errors );
69- }
70-
71- #[Test]
72- public function itValidatesAValueWithASingleParametrizedRule () {
73- $ validatorFactory = new ValidatorsFactory ();
74- $ validator = $ validatorFactory ->create ('max:30 ' );
75- $ errors = $ validator ->validate ('something ' );
76- $ this ->assertEmpty ($ errors );
77- }
77+ #[Test]
78+ public function itValidatesAValueWithASingleParametrizedRule ()
79+ {
80+ $ validatorFactory = new ValidatorsFactory ();
81+ $ validator = $ validatorFactory ->create ('max:30 ' );
82+ $ errors = $ validator ->validate ('something ' );
83+ $ this ->assertEmpty ($ errors );
84+ }
7885
79- }
86+ }
0 commit comments