Bez popisu

ComparatorTest.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Symfony\Component\Finder\Comparator\Comparator;
  12. class ComparatorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testGetSetOperator()
  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. $comparator = new Comparator();
  24. $comparator->setOperator('>');
  25. $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
  26. }
  27. public function testGetSetTarget()
  28. {
  29. $comparator = new Comparator();
  30. $comparator->setTarget(8);
  31. $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target');
  32. }
  33. /**
  34. * @dataProvider getTestData
  35. */
  36. public function testTest($operator, $target, $match, $noMatch)
  37. {
  38. $c = new Comparator();
  39. $c->setOperator($operator);
  40. $c->setTarget($target);
  41. foreach ($match as $m) {
  42. $this->assertTrue($c->test($m), '->test() tests a string against the expression');
  43. }
  44. foreach ($noMatch as $m) {
  45. $this->assertFalse($c->test($m), '->test() tests a string against the expression');
  46. }
  47. }
  48. public function getTestData()
  49. {
  50. return array(
  51. array('<', '1000', array('500', '999'), array('1000', '1500')),
  52. );
  53. }
  54. }