|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Coduo\PHPMatcher\Tests\Matcher; |
| 4 | + |
| 5 | +use Coduo\PHPMatcher\Matcher\UuidMatcher; |
| 6 | + |
| 7 | +class UuidMatcherTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @var UuidMatcher |
| 11 | + */ |
| 12 | + private $matcher; |
| 13 | + |
| 14 | + public function setUp() |
| 15 | + { |
| 16 | + $this->matcher = new UuidMatcher(); |
| 17 | + } |
| 18 | + /** |
| 19 | + * @dataProvider positiveCanMatchData |
| 20 | + */ |
| 21 | + public function test_positive_can_matches($pattern) |
| 22 | + { |
| 23 | + $this->assertTrue($this->matcher->canMatch($pattern)); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @dataProvider negativeCanMatchData |
| 28 | + */ |
| 29 | + public function test_negative_can_matches($pattern) |
| 30 | + { |
| 31 | + $this->assertFalse($this->matcher->canMatch($pattern)); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @dataProvider positiveMatchData |
| 36 | + */ |
| 37 | + public function test_positive_match($value, $pattern) |
| 38 | + { |
| 39 | + $this->assertTrue($this->matcher->match($value, $pattern)); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @dataProvider negativeMatchData |
| 44 | + */ |
| 45 | + public function test_negative_match($value, $pattern) |
| 46 | + { |
| 47 | + $this->assertFalse($this->matcher->match($value, $pattern)); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @dataProvider negativeMatchDescription |
| 52 | + */ |
| 53 | + public function test_negative_match_description($value, $pattern, $error) |
| 54 | + { |
| 55 | + $this->matcher->match($value, $pattern); |
| 56 | + $this->assertEquals($error, $this->matcher->getError()); |
| 57 | + } |
| 58 | + |
| 59 | + public static function positiveCanMatchData() |
| 60 | + { |
| 61 | + return array( |
| 62 | + array("@uuid@"), |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + public static function positiveMatchData() |
| 67 | + { |
| 68 | + return array( |
| 69 | + array("9f4db639-0e87-4367-9beb-d64e3f42ae18", "@uuid@"), |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + public static function negativeCanMatchData() |
| 74 | + { |
| 75 | + return array( |
| 76 | + array("@uuid"), |
| 77 | + array("uuid"), |
| 78 | + array(1), |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + public static function negativeMatchData() |
| 83 | + { |
| 84 | + return array( |
| 85 | + array(1, "@uuid@"), |
| 86 | + array(0, "@uuid@"), |
| 87 | + array("9f4d-b639-0e87-4367-9beb-d64e3f42ae18", "@uuid@"), |
| 88 | + array("9f4db639-0e87-4367-9beb-d64e3f42ae1", "@uuid@"), |
| 89 | + array("9f4db639-0e87-4367-9beb-d64e3f42ae181", "@uuid@"), |
| 90 | + array("9f4db6390e8743679bebd64e3f42ae18", "@uuid@"), |
| 91 | + array("9f4db6390e87-4367-9beb-d64e-3f42ae18", "@uuid@"), |
| 92 | + array("9f4db639-0e87-4367-9beb-d64e3f42ae1g", "@uuid@"), |
| 93 | + array("9f4db639-0e87-0367-9beb-d64e3f42ae18", "@uuid@"), |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + public static function negativeMatchDescription() |
| 98 | + { |
| 99 | + return array( |
| 100 | + array(new \stdClass, "@uuid@", "object \"\\stdClass\" is not a valid UUID: not a string."), |
| 101 | + array(1.1, "@uuid@", "double \"1.1\" is not a valid UUID: not a string."), |
| 102 | + array(false, "@uuid@", "boolean \"false\" is not a valid UUID: not a string."), |
| 103 | + array(1, "@uuid@", "integer \"1\" is not a valid UUID: not a string."), |
| 104 | + array("lorem ipsum", "@uuid@", "string \"lorem ipsum\" is not a valid UUID: invalid format."), |
| 105 | + array("9f4db639-0e87-4367-9beb-d64e3f42ae1z", "@uuid@", "string \"9f4db639-0e87-4367-9beb-d64e3f42ae1z\" is not a valid UUID: invalid format."), |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
0 commit comments