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\Comparator;
|
Chris@0
|
16
|
Chris@0
|
17 class ComparatorTest extends TestCase
|
Chris@0
|
18 {
|
Chris@0
|
19 public function testGetSetOperator()
|
Chris@0
|
20 {
|
Chris@0
|
21 $comparator = new Comparator();
|
Chris@0
|
22 try {
|
Chris@0
|
23 $comparator->setOperator('foo');
|
Chris@0
|
24 $this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
|
Chris@0
|
25 } catch (\Exception $e) {
|
Chris@0
|
26 $this->assertInstanceOf('InvalidArgumentException', $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 $comparator = new Comparator();
|
Chris@0
|
30 $comparator->setOperator('>');
|
Chris@0
|
31 $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 public function testGetSetTarget()
|
Chris@0
|
35 {
|
Chris@0
|
36 $comparator = new Comparator();
|
Chris@0
|
37 $comparator->setTarget(8);
|
Chris@0
|
38 $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target');
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * @dataProvider getTestData
|
Chris@0
|
43 */
|
Chris@0
|
44 public function testTest($operator, $target, $match, $noMatch)
|
Chris@0
|
45 {
|
Chris@0
|
46 $c = new Comparator();
|
Chris@0
|
47 $c->setOperator($operator);
|
Chris@0
|
48 $c->setTarget($target);
|
Chris@0
|
49
|
Chris@0
|
50 foreach ($match as $m) {
|
Chris@0
|
51 $this->assertTrue($c->test($m), '->test() tests a string against the expression');
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 foreach ($noMatch as $m) {
|
Chris@0
|
55 $this->assertFalse($c->test($m), '->test() tests a string against the expression');
|
Chris@0
|
56 }
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 public function getTestData()
|
Chris@0
|
60 {
|
Chris@17
|
61 return [
|
Chris@17
|
62 ['<', '1000', ['500', '999'], ['1000', '1500']],
|
Chris@17
|
63 ];
|
Chris@0
|
64 }
|
Chris@0
|
65 }
|