|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Coduo\PHPMatcher\Tests; |
| 6 | + |
| 7 | +use Coduo\PHPMatcher\Factory\SimpleFactory; |
| 8 | +use Coduo\PHPMatcher\Matcher; |
| 9 | +use Coduo\PHPMatcher\PHPMatcher; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +final class ExpandersTest extends TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var Matcher |
| 16 | + */ |
| 17 | + protected $matcher; |
| 18 | + |
| 19 | + public function setUp() : void |
| 20 | + { |
| 21 | + $factory = new SimpleFactory(); |
| 22 | + $this->matcher = $factory->createMatcher(); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @dataProvider expanderExamples() |
| 27 | + */ |
| 28 | + public function test_expanders($value, $pattern, $expectedResult) |
| 29 | + { |
| 30 | + $this->assertSame($expectedResult, $this->matcher->match($value, $pattern)); |
| 31 | + $this->assertSame($expectedResult, PHPMatcher::match($value, $pattern)); |
| 32 | + } |
| 33 | + |
| 34 | + public static function expanderExamples() |
| 35 | + { |
| 36 | + return [ |
| 37 | + [ 'lorem ipsum', '@[email protected]("lorem")', true], |
| 38 | + [ 'lorem ipsum', '@[email protected]("LOREM", true)', true], |
| 39 | + [ 'lorem ipsum', '@[email protected]("ipsum")', true], |
| 40 | + [ 'lorem ipsum', '@[email protected]("IPSUM", true)', true], |
| 41 | + [ 'lorem ipsum', '@[email protected]("lorem")', true], |
| 42 | + |
| 43 | + [ 'lorem ipsum', '@[email protected]()', false], |
| 44 | + [ 'http://coduo.pl/', '@[email protected]()', true], |
| 45 | + [ 'lorem ipsum', '@[email protected]()', false], |
| 46 | + [ '2014-08-19', '@[email protected]()', true], |
| 47 | + [ '3014-08-19', '@[email protected]("today")', false], |
| 48 | + [ '1014-08-19', '@[email protected]("+ 1day")', true], |
| 49 | + [ '3014-08-19', '@[email protected]("today")', true], |
| 50 | + [ '1014-08-19', '@[email protected]("+ 1day")', false], |
| 51 | + [ 100, '@[email protected](101).greaterThan(10)', true], |
| 52 | + [ '', '@[email protected]()', false], |
| 53 | + [ 'lorem ipsum', '@[email protected]()', true], |
| 54 | + [ '', '@[email protected]()', true], |
| 55 | + [[ 'foo', 'bar'], '@[email protected]("bar")', true], |
| 56 | + [[], '@[email protected]()', true], |
| 57 | + [[ 'foo'], '@[email protected]()', false], |
| 58 | + [[ 1, 2, 3], '@[email protected](3)', true], |
| 59 | + [[ 1, 2, 3], '@[email protected](4)', false], |
| 60 | + [ 'lorem ipsum', '@[email protected](contains("lorem"), contains("test"))', true], |
| 61 | + [ 'lorem ipsum', '@[email protected](contains("lorem"), contains("test")).endsWith("ipsum")', true], |
| 62 | + [ 'lorem ipsum', '@[email protected]("/^lorem \\w+$/")', true], |
| 63 | + [ 'lorem ipsum', '@[email protected]("/^foo/")', false], |
| 64 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 65 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 66 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 67 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 68 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 69 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 70 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 71 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 72 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 73 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 74 | + [[], [ 'unexistent_key' => '@[email protected]()'], true], |
| 75 | + [[ 'Norbert', 'Michał'], '@[email protected]("@string@")', true], |
| 76 | + [ '127.0.0.1', '@[email protected]()', true], |
| 77 | + [ '2001:0db8:0000:42a1:0000:0000:ab1c:0001', '@[email protected]()', true], |
| 78 | + [ '127.255.999.999', '@[email protected]()', false], |
| 79 | + [ 'foo:bar:42:42', '@[email protected]()', false], |
| 80 | + ]; |
| 81 | + } |
| 82 | +} |
0 commit comments