@@ -18,19 +18,20 @@ class ComparatorTest extends TestCase
18
18
{
19
19
public function testGetSetOperator ()
20
20
{
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
-
29
21
$ comparator = new Comparator ();
30
22
$ comparator ->setOperator ('> ' );
31
23
$ this ->assertEquals ('> ' , $ comparator ->getOperator (), '->getOperator() returns the current operator ' );
32
24
}
33
25
26
+ public function testInvalidOperator ()
27
+ {
28
+ $ comparator = new Comparator ();
29
+
30
+ $ t
10000
his ->expectException (\InvalidArgumentException::class);
31
+ $ this ->expectExceptionMessage ('Invalid operator "foo". ' );
32
+ $ comparator ->setOperator ('foo ' );
33
+ }
34
+
34
35
public function testGetSetTarget ()
35
36
{
36
37
$ comparator = new Comparator ();
@@ -39,27 +40,55 @@ public function testGetSetTarget()
39
40
}
40
41
41
42
/**
42
- * @dataProvider getTestData
43
+ * @dataProvider provideMatches
43
44
*/
44
- public function testTest ( $ operator , $ target , $ match , $ noMatch )
45
+ public function testTestSucceeds ( string $ operator , string $ target , string $ testedValue )
45
46
{
46
47
$ c = new Comparator ();
47
48
$ c ->setOperator ($ operator );
48
49
$ c ->setTarget ($ target );
49
50
50
- foreach ($ match as $ 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 );
53
78
54
- foreach ($ noMatch as $ m ) {
55
- $ this ->assertFalse ($ c ->test ($ m ), '->test() tests a string against the expression ' );
56
- }
79
+ $ this ->assertFalse ($ c ->test ($ testedValue ));
57
80
}
58
81
59
- public function getTestData ()
82
+ public function provideNonMatches (): array
60
83
{
61
84
return [
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 ' ],
63
92
];
64
93
}
65
94
}
31C2 0 commit comments