4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests\Comparator;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Comparator\Comparator;
17 class ComparatorTest extends TestCase
19 public function testGetSetOperator()
21 $comparator = new Comparator();
23 $comparator->setOperator('foo');
24 $this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
25 } catch (\Exception $e) {
26 $this->assertInstanceOf('InvalidArgumentException', $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
29 $comparator = new Comparator();
30 $comparator->setOperator('>');
31 $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
34 public function testGetSetTarget()
36 $comparator = new Comparator();
37 $comparator->setTarget(8);
38 $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target');
42 * @dataProvider getTestData
44 public function testTest($operator, $target, $match, $noMatch)
46 $c = new Comparator();
47 $c->setOperator($operator);
48 $c->setTarget($target);
50 foreach ($match as $m) {
51 $this->assertTrue($c->test($m), '->test() tests a string against the expression');
54 foreach ($noMatch as $m) {
55 $this->assertFalse($c->test($m), '->test() tests a string against the expression');
59 public function getTestData()
62 array('<', '1000', array('500', '999'), array('1000', '1500')),