ExpressionTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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;
  11. use Symfony\Component\Finder\Expression\Expression;
  12. class ExpressionTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getTypeGuesserData
  16. */
  17. public function testTypeGuesser($expr, $type)
  18. {
  19. $this->assertEquals($type, Expression::create($expr)->getType());
  20. }
  21. /**
  22. * @dataProvider getCaseSensitiveData
  23. */
  24. public function testCaseSensitive($expr, $isCaseSensitive)
  25. {
  26. $this->assertEquals($isCaseSensitive, Expression::create($expr)->isCaseSensitive());
  27. }
  28. /**
  29. * @dataProvider getRegexRenderingData
  30. */
  31. public function testRegexRendering($expr, $body)
  32. {
  33. $this->assertEquals($body, Expression::create($expr)->renderPattern());
  34. }
  35. public function getTypeGuesserData()
  36. {
  37. return array(
  38. array('{foo}', Expression::TYPE_REGEX),
  39. array('/foo/', Expression::TYPE_REGEX),
  40. array('foo', Expression::TYPE_GLOB),
  41. array('foo*', Expression::TYPE_GLOB),
  42. );
  43. }
  44. public function getCaseSensitiveData()
  45. {
  46. return array(
  47. array('{foo}m', true),
  48. array('/foo/i', false),
  49. array('foo*', true),
  50. );
  51. }
  52. public function getRegexRenderingData()
  53. {
  54. return array(
  55. array('{foo}m', 'foo'),
  56. array('/foo/i', 'foo'),
  57. );
  58. }
  59. }