Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Comparator / ComparatorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Finder\Tests\Comparator;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Comparator\Comparator;
16
17 class ComparatorTest extends TestCase
18 {
19     public function testGetSetOperator()
20     {
21         $comparator = new Comparator();
22         try {
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.');
27         }
28
29         $comparator = new Comparator();
30         $comparator->setOperator('>');
31         $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
32     }
33
34     public function testGetSetTarget()
35     {
36         $comparator = new Comparator();
37         $comparator->setTarget(8);
38         $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target');
39     }
40
41     /**
42      * @dataProvider getTestData
43      */
44     public function testTest($operator, $target, $match, $noMatch)
45     {
46         $c = new Comparator();
47         $c->setOperator($operator);
48         $c->setTarget($target);
49
50         foreach ($match as $m) {
51             $this->assertTrue($c->test($m), '->test() tests a string against the expression');
52         }
53
54         foreach ($noMatch as $m) {
55             $this->assertFalse($c->test($m), '->test() tests a string against the expression');
56         }
57     }
58
59     public function getTestData()
60     {
61         return array(
62             array('<', '1000', array('500', '999'), array('1000', '1500')),
63         );
64     }
65 }