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@17: return [ Chris@17: ['< 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]], Chris@17: ['until 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]], Chris@17: ['before 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]], Chris@17: ['> 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]], Chris@17: ['after 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]], Chris@17: ['since 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]], Chris@17: ['!= 2005-10-10', [strtotime('2005-10-11')], [strtotime('2005-10-10')]], Chris@17: ]; Chris@0: } Chris@0: }