|
| 1 | +<?php |
| 2 | +namespace JsonMatcher\Tests\Matcher; |
| 3 | + |
| 4 | +use JsonMatcher\Matcher\ExpressionMatcher; |
| 5 | + |
| 6 | +class ExpressionMatcherTest extends \PHPUnit_Framework_TestCase |
| 7 | +{ |
| 8 | + /** |
| 9 | + * @dataProvider positiveCanMatchData |
| 10 | + */ |
| 11 | + public function test_positive_can_matches($pattern) |
| 12 | + { |
| 13 | + $matcher = new ExpressionMatcher(); |
| 14 | + $this->assertTrue($matcher->canMatch($pattern)); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * @dataProvider negativeCanMatchData |
| 19 | + */ |
| 20 | + public function test_negative_can_matches($pattern) |
| 21 | + { |
| 22 | + $matcher = new ExpressionMatcher(); |
| 23 | + $this->assertFalse($matcher->canMatch($pattern)); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @dataProvider positiveMatchData |
| 28 | + */ |
| 29 | + public function test_positive_match($value, $pattern) |
| 30 | + { |
| 31 | + $matcher = new ExpressionMatcher(); |
| 32 | + $this->assertTrue($matcher->match($value, $pattern)); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @dataProvider negativeMatchData |
| 37 | + */ |
| 38 | + public function test_negative_match($value, $pattern) |
| 39 | + { |
| 40 | + $matcher = new ExpressionMatcher(); |
| 41 | + $this->assertFalse($matcher->match($value, $pattern)); |
| 42 | + } |
| 43 | + |
| 44 | + public static function positiveCanMatchData() |
| 45 | + { |
| 46 | + return array( |
| 47 | + array("expr(1 > 2)"), |
| 48 | + array("expr(value == 'foo')"), |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + public static function negativeCanMatchData() |
| 53 | + { |
| 54 | + return array( |
| 55 | + array("@integer"), |
| 56 | + array("expr("), |
| 57 | + array("@string"), |
| 58 | + array(new \stdClass), |
| 59 | + array(array("foobar")) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + public static function positiveMatchData() |
| 64 | + { |
| 65 | + return array( |
| 66 | + array(4, "expr(value > 2)"), |
| 67 | + array("foo", "expr(value == 'foo')"), |
| 68 | + array(new \DateTime('2014-04-01'), "expr(value.format('Y-m-d') == '2014-04-01')") |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + public static function negativeMatchData() |
| 73 | + { |
| 74 | + return array( |
| 75 | + array(4, "expr(value < 2)"), |
| 76 | + array("foo", "expr(value != 'foo')"), |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments