@@ -18,19 +18,20 @@ class ComparatorTest extends TestCase
1818{
1919public function testGetSetOperator ()
2020 {
21- $ comparator =new Comparator ();
22- try {
23- $ comparator ->setOperator ('foo ' );
24- $ this ->fail ('->setOperator() throws an \InvalidArgumentException if the operator is not valid. ' );
25- }catch (\Exception $ e ) {
26- $ this ->assertInstanceOf (\InvalidArgumentException::class,$ e ,'->setOperator() throws an \InvalidArgumentException if the operator is not valid. ' );
27- }
28-
2921$ comparator =new Comparator ();
3022$ comparator ->setOperator ('> ' );
3123$ this ->assertEquals ('> ' ,$ comparator ->getOperator (),'->getOperator() returns the current operator ' );
3224 }
3325
26+ public function testInvalidOperator ()
27+ {
28+ $ comparator =new Comparator ();
29+
30+ $ this ->expectException (\InvalidArgumentException::class);
31+ $ this ->expectExceptionMessage ('Invalid operator "foo". ' );
32+ $ comparator ->setOperator ('foo ' );
33+ }
34+
3435public function testGetSetTarget ()
3536 {
3637$ comparator =new Comparator ();
@@ -39,27 +40,55 @@ public function testGetSetTarget()
3940 }
4041
4142/**
42- * @dataProvidergetTestData
43+ * @dataProviderprovideMatches
4344 */
44- public function testTest ( $ operator ,$ target ,$ match , $ noMatch )
45+ public function testTestSucceeds ( string $ operator ,string $ target ,string $ testedValue )
4546 {
4647$ c =new Comparator ();
4748$ c ->setOperator ($ operator );
4849$ c ->setTarget ($ target );
4950
50- foreach ($ matchas $ m ) {
51- $ this ->assertTrue ($ c ->test ($ m ),'->test() tests a string against the expression ' );
52- }
51+ $ this ->assertTrue ($ c ->test ($ testedValue ));
52+ }
53+
54+ public function provideMatches ():array
55+ {
56+ return [
57+ ['< ' ,'1000 ' ,'500 ' ],
58+ ['< ' ,'1000 ' ,'999 ' ],
59+ ['<= ' ,'1000 ' ,'999 ' ],
60+ ['!= ' ,'1000 ' ,'999 ' ],
61+ ['<= ' ,'1000 ' ,'1000 ' ],
62+ ['== ' ,'1000 ' ,'1000 ' ],
63+ ['>= ' ,'1000 ' ,'1000 ' ],
64+ ['>= ' ,'1000 ' ,'1001 ' ],
65+ ['> ' ,'1000 ' ,'1001 ' ],
66+ ['> ' ,'1000 ' ,'5000 ' ],
67+ ];
68+ }
69+
70+ /**
71+ * @dataProvider provideNonMatches
72+ */
73+ public function testTestFails (string $ operator ,string $ target ,string $ testedValue )
74+ {
75+ $ c =new Comparator ();
76+ $ c ->setOperator ($ operator );
77+ $ c ->setTarget ($ target );
5378
54- foreach ($ noMatchas $ m ) {
55- $ this ->assertFalse ($ c ->test ($ m ),'->test() tests a string against the expression ' );
56- }
79+ $ this ->assertFalse ($ c ->test ($ testedValue ));
5780 }
5881
59- public function getTestData ()
82+ public function provideNonMatches (): array
6083 {
6184return [
62- ['< ' ,'1000 ' , ['500 ' ,'999 ' ], ['1000 ' ,'1500 ' ]],
85+ ['> ' ,'1000 ' ,'500 ' ],
86+ ['>= ' ,'1000 ' ,'500 ' ],
87+ ['> ' ,'1000 ' ,'1000 ' ],
88+ ['!= ' ,'1000 ' ,'1000 ' ],
89+ ['< ' ,'1000 ' ,'1000 ' ],
90+ ['< ' ,'1000 ' ,'1500 ' ],
91+ ['<= ' ,'1000 ' ,'1500 ' ],
6392 ];
6493 }
6594}