Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Finder\Tests\Comparator; Chris@0: Chris@0: use PHPUnit\Framework\TestCase; Chris@0: use Symfony\Component\Finder\Comparator\DateComparator; Chris@0: Chris@0: class DateComparatorTest extends TestCase Chris@0: { Chris@0: public function testConstructor() Chris@0: { Chris@0: try { Chris@0: new DateComparator('foobar'); Chris@0: $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); Chris@0: } catch (\Exception $e) { Chris@0: $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); Chris@0: } Chris@0: Chris@0: try { Chris@0: new DateComparator(''); Chris@0: $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); Chris@0: } catch (\Exception $e) { Chris@0: $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider getTestData Chris@0: */ Chris@0: public function testTest($test, $match, $noMatch) Chris@0: { Chris@0: $c = new DateComparator($test); Chris@0: Chris@0: foreach ($match as $m) { Chris@0: $this->assertTrue($c->test($m), '->test() tests a string against the expression'); Chris@0: } Chris@0: Chris@0: foreach ($noMatch as $m) { Chris@0: $this->assertFalse($c->test($m), '->test() tests a string against the expression'); Chris@0: } Chris@0: } Chris@0: Chris@0: public function getTestData() Chris@0: { Chris@0: return array( Chris@0: array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), Chris@0: array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), Chris@0: array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), Chris@0: array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), Chris@0: array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), Chris@0: array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), Chris@0: array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))), Chris@0: ); Chris@0: } Chris@0: }