ComparatorTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Tests\Components\Finder\Comparator;
  11. use Symfony\Components\Finder\Comparator\Comparator;
  12. class ComparatorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testSetOperator()
  15. {
  16. $comparator = new Comparator();
  17. try {
  18. $comparator->setOperator('foo');
  19. $this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
  20. } catch (\Exception $e) {
  21. $this->assertInstanceOf('InvalidArgumentException', $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
  22. }
  23. }
  24. /**
  25. * @dataProvider getTestData
  26. */
  27. public function testTest($operator, $target, $match, $noMatch)
  28. {
  29. $c = new Comparator();
  30. $c->setOperator($operator);
  31. $c->setTarget($target);
  32. foreach ($match as $m) {
  33. $this->assertTrue($c->test($m), '->test() tests a string against the expression');
  34. }
  35. foreach ($noMatch as $m) {
  36. $this->assertFalse($c->test($m), '->test() tests a string against the expression');
  37. }
  38. }
  39. public function getTestData()
  40. {
  41. return array(
  42. array('<', '1000', array('500', '999'), array('1000', '1500')),
  43. );
  44. }
  45. }