|
1 | 1 | <?php
|
2 | 2 | namespace JsonMatcher\Tests;
|
3 | 3 |
|
4 |
| -use JsonMatcher\Matcher; |
| 4 | +use JsonMatcher\Matcher\ScalarMatcher; |
5 | 5 |
|
6 | 6 | class ScalarMatcherTest extends \PHPUnit_Framework_TestCase
|
7 | 7 | {
|
8 |
| - public function test_match_scalars() |
| 8 | + /** |
| 9 | + * @dataProvider positiveCanMatches |
| 10 | + */ |
| 11 | + public function test_positive_can_matches($pattern) |
9 | 12 | {
|
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 | + } |
11 | 43 |
|
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 | + ); |
16 | 81 | }
|
17 | 82 | }
|
0 commit comments