ComparatorTest.php 1.9 KB

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