annotate vendor/symfony/finder/Tests/Comparator/DateComparatorTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
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@0 54 return array(
Chris@0 55 array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
Chris@0 56 array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
Chris@0 57 array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
Chris@0 58 array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
Chris@0 59 array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
Chris@0 60 array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
Chris@0 61 array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))),
Chris@0 62 );
Chris@0 63 }
Chris@0 64 }