|
| 1 | +<?php |
| 2 | +namespace Coduo\PHPMatcher\Tests\Matcher; |
| 3 | + |
| 4 | +use Coduo\PHPMatcher\Matcher\NullMatcher; |
| 5 | + |
| 6 | +class NullMatcherTest extends \PHPUnit_Framework_TestCase |
| 7 | +{ |
| 8 | + /** |
| 9 | + * @dataProvider positiveCanMatchData |
| 10 | + */ |
| 11 | + public function test_positive_can_matches($pattern) |
| 12 | + { |
| 13 | + $matcher = new NullMatcher(); |
| 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 NullMatcher(); |
| 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 NullMatcher(); |
| 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 NullMatcher(); |
| 41 | + $this->assertFalse($matcher->match($value, $pattern)); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @dataProvider negativeMatchDescription |
| 46 | + */ |
| 47 | + public function test_negative_match_description($value, $pattern, $error) |
| 48 | + { |
| 49 | + $matcher = new NullMatcher(); |
| 50 | + $matcher->match($value, $pattern); |
| 51 | + $this->assertEquals($error, $matcher->getError()); |
| 52 | + } |
| 53 | + |
| 54 | + public static function positiveCanMatchData() |
| 55 | + { |
| 56 | + return array( |
| 57 | + array("@null@") |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public static function positiveMatchData() |
| 62 | + { |
| 63 | + return array( |
| 64 | + array(null, "@null@"), |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + public static function negativeCanMatchData() |
| 69 | + { |
| 70 | + return array( |
| 71 | + array("@null"), |
| 72 | + array("null"), |
| 73 | + array(0) |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + public static function negativeMatchData() |
| 78 | + { |
| 79 | + return array( |
| 80 | + array("null", "@null@"), |
| 81 | + array(0, "@null@") |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public static function negativeMatchDescription() |
| 86 | + { |
| 87 | + return array( |
| 88 | + array("test", "@boolean@", "string \"test\" does not match null."), |
| 89 | + array(new \stdClass, "@string@", "object \"\\stdClass\" does not match null."), |
| 90 | + array(1.1, "@integer@", "double \"1.1\" does not match null."), |
| 91 | + array(false, "@double@", "boolean \"false\" does not match null."), |
| 92 | + array(1, "@array@", "integer \"1\" does not match null.") |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments