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