|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander; |
| 6 | + |
| 7 | +use Coduo\PHPMatcher\Matcher\Pattern\Expander\Before; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class BeforeTest extends TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @dataProvider examplesProvider |
| 14 | + */ |
| 15 | + public function test_examples($boundary, $value, $expectedResult) |
| 16 | + { |
| 17 | + $expander = new Before($boundary); |
| 18 | + $this->assertEquals($expectedResult, $expander->match($value)); |
| 19 | + } |
| 20 | + |
| 21 | + public static function examplesProvider() |
| 22 | + { |
| 23 | + return [ |
| 24 | + ['+ 2 day','today',true], |
| 25 | + ['2018-02-06T04:20:33','2017-02-06T04:20:33',true], |
| 26 | + ['2017-02-06T04:20:33','2018-02-06T04:20:33',false], |
| 27 | + ]; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @dataProvider invalidCasesProvider |
| 32 | + */ |
| 33 | + public function test_error_when_matching_fail($boundary, $value, $errorMessage) |
| 34 | + { |
| 35 | + $expander = new Before($boundary); |
| 36 | + $this->assertFalse($expander->match($value)); |
| 37 | + $this->assertEquals($errorMessage, $expander->getError()); |
| 38 | + } |
| 39 | + |
| 40 | + public static function invalidCasesProvider() |
| 41 | + { |
| 42 | + return [ |
| 43 | + ['today', 'ipsum lorem', 'Value "ipsum lorem" is not a valid date.'], |
| 44 | + ['2017-02-06T04:20:33', 'ipsum lorem', 'Value "ipsum lorem" is not a valid date.'], |
| 45 | + ['today',5, 'Before expander require "string", got "5".'], |
| 46 | + ]; |
| 47 | + } |
| 48 | +} |
0 commit comments