annotate vendor/symfony/finder/Tests/Comparator/DateComparatorTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Finder\Tests\Comparator;
Chris@0 13
Chris@0 14 use PHPUnit\Framework\TestCase;
Chris@0 15 use Symfony\Component\Finder\Comparator\DateComparator;
Chris@0 16
Chris@0 17 class DateComparatorTest extends TestCase
Chris@0 18 {
Chris@0 19 public function testConstructor()
Chris@0 20 {
Chris@0 21 try {
Chris@0 22 new DateComparator('foobar');
Chris@0 23 $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
Chris@0 24 } catch (\Exception $e) {
Chris@0 25 $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
Chris@0 26 }
Chris@0 27
Chris@0 28 try {
Chris@0 29 new DateComparator('');
Chris@0 30 $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
Chris@0 31 } catch (\Exception $e) {
Chris@0 32 $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
Chris@0 33 }
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * @dataProvider getTestData
Chris@0 38 */
Chris@0 39 public function testTest($test, $match, $noMatch)
Chris@0 40 {
Chris@0 41 $c = new DateComparator($test);
Chris@0 42
Chris@0 43 foreach ($match as $m) {
Chris@0 44 $this->assertTrue($c->test($m), '->test() tests a string against the expression');
Chris@0 45 }
Chris@0 46
Chris@0 47 foreach ($noMatch as $m) {
Chris@0 48 $this->assertFalse($c->test($m), '->test() tests a string against the expression');
Chris@0 49 }
Chris@0 50 }
Chris@0 51
Chris@0 52 public function getTestData()
Chris@0 53 {
Chris@17 54 return [
Chris@17 55 ['< 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
Chris@17 56 ['until 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
Chris@17 57 ['before 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
Chris@17 58 ['> 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
Chris@17 59 ['after 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
Chris@17 60 ['since 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
Chris@17 61 ['!= 2005-10-10', [strtotime('2005-10-11')], [strtotime('2005-10-10')]],
Chris@17 62 ];
Chris@0 63 }
Chris@0 64 }