Skip to content

Commit 3d19b39

Browse files
committed
Refactoring scalar matcher test
1 parent babdb07 commit 3d19b39

File tree

1 file changed

+72
-7
lines changed

1 file changed

+72
-7
lines changed
Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,82 @@
11
<?php
22
namespace JsonMatcher\Tests;
33

4-
use JsonMatcher\Matcher;
4+
use JsonMatcher\Matcher\ScalarMatcher;
55

66
class ScalarMatcherTest extends \PHPUnit_Framework_TestCase
77
{
8-
public function test_match_scalars()
8+
/**
9+
* @dataProvider positiveCanMatches
10+
*/
11+
public function test_positive_can_matches($pattern)
912
{
10-
$matcher = new Matcher\ScalarMatcher();
13+
$matcher = new ScalarMatcher();
14+
$this->assertTrue($matcher->canMatch($pattern));
15+
}
16+
17+
/**
18+
* @dataProvider negativeCanMatches
19+
*/
20+
public function test_negative_can_matches($pattern)
21+
{
22+
$matcher = new ScalarMatcher();
23+
$this->assertFalse($matcher->canMatch($pattern));
24+
}
25+
26+
/**
27+
* @dataProvider positiveMatches
28+
*/
29+
public function test_positive_matches($value, $pattern)
30+
{
31+
$matcher = new ScalarMatcher();
32+
$this->assertTrue($matcher->match($value, $pattern));
33+
}
34+
35+
/**
36+
* @dataProvider negativeMatches
37+
*/
38+
public function test_negative_matches($value, $pattern)
39+
{
40+
$matcher = new ScalarMatcher();
41+
$this->assertFalse($matcher->match($value, $pattern));
42+
}
1143

12-
$this->assertTrue($matcher->match(1, 1));
13-
$this->assertTrue($matcher->match("michal", "michal"));
14-
$this->assertFalse($matcher->match(false, "false"));
15-
$this->assertFalse($matcher->match(false, 0));
44+
public static function negativeMatches()
45+
{
46+
return array(
47+
array(false, "false"),
48+
array(false, 0),
49+
array(true, 1),
50+
array("array", array()),
51+
);
52+
}
53+
54+
public static function positiveMatches()
55+
{
56+
return array(
57+
array(1, 1),
58+
array("michal", "michal"),
59+
array(false, false),
60+
array(6.66, 6.66),
61+
);
62+
}
63+
64+
public static function positiveCanMatches()
65+
{
66+
return array(
67+
array(1),
68+
array("michal"),
69+
array(true),
70+
array(false),
71+
array(6.66),
72+
);
73+
}
74+
75+
public static function negativeCanMatches()
76+
{
77+
return array(
78+
array(new \stdClass),
79+
array(array())
80+
);
1681
}
1782
}

0 commit comments

Comments
 (0)