|
| 1 | +<?php |
| 2 | +namespace Coduo\PHPMatcher\Tests\Matcher; |
| 3 | + |
| 4 | +use Coduo\PHPMatcher\Matcher\TypeMatcher; |
| 5 | + |
| 6 | +class TypeMatcherTest extends \PHPUnit_Framework_TestCase |
| 7 | +{ |
| 8 | + /** |
| 9 | + * @dataProvider positiveCanMatchData |
| 10 | + */ |
| 11 | + public function test_positive_can_matches($pattern) |
| 12 | + { |
| 13 | + $matcher = new TypeMatcher(); |
| 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 TypeMatcher(); |
| 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 TypeMatcher(); |
| 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 TypeMatcher(); |
| 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 TypeMatcher(); |
| 50 | + $matcher->match($value, $pattern); |
| 51 | + $this->assertEquals($error, $matcher->getError()); |
| 52 | + } |
| 53 | + |
| 54 | + public static function positiveCanMatchData() |
| 55 | + { |
| 56 | + return array( |
| 57 | + array("@integer@"), |
| 58 | + array("@string@"), |
| 59 | + array("@boolean@"), |
| 60 | + array("@double@"), |
| 61 | + array("@array@") |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + public static function positiveMatchData() |
| 66 | + { |
| 67 | + return array( |
| 68 | + array(false, "@boolean@"), |
| 69 | + array("Norbert", "@string@"), |
| 70 | + array(1, "@integer@"), |
| 71 | + array(6.66, "@double@"), |
| 72 | + array(array('test'), '@array@') |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public static function negativeCanMatchData() |
| 77 | + { |
| 78 | + return array( |
| 79 | + array("@integer"), |
| 80 | + array("qweqwe"), |
| 81 | + array(1), |
| 82 | + array("@string"), |
| 83 | + array(new \stdClass), |
| 84 | + array(array("foobar")) |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + public static function negativeMatchData() |
| 89 | + { |
| 90 | + return array( |
| 91 | + array("test", "@boolean@"), |
| 92 | + array(new \stdClass, "@string@"), |
| 93 | + array(1.1, "@integer@"), |
| 94 | + array(false, "@double@"), |
| 95 | + array(1, "@array@") |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + public static function negativeMatchDescription() |
| 100 | + { |
| 101 | + return array( |
| 102 | + array("test", "@boolean@", "string \"test\" does not match @boolean@ pattern."), |
| 103 | + array(new \stdClass, "@string@", "object \"\\stdClass\" does not match @string@ pattern."), |
| 104 | + array(1.1, "@integer@", "double \"1.1\" does not match @integer@ pattern."), |
| 105 | + array(false, "@double@", "boolean \"false\" does not match @double@ pattern."), |
| 106 | + array(1, "@array@", "integer \"1\" does not match @array@ pattern.") |
| 107 | + ); |
| 108 | + } |
| 109 | +} |
0 commit comments