PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Symfony/Component/Finder/Tests/GlobTest.php

http://github.com/symfony/symfony
PHP | 95 lines | 71 code | 16 blank | 8 comment | 4 complexity | 6973eece42d88ac65385b6d904ef2cc1 MD5 | raw file
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Finder\Finder;
  13. use Symfony\Component\Finder\Glob;
  14. class GlobTest extends TestCase
  15. {
  16. public function testGlobToRegexDelimiters()
  17. {
  18. $this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#'));
  19. $this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*'));
  20. $this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, ''));
  21. $this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/'));
  22. }
  23. public function testGlobToRegexDoubleStarStrictDots()
  24. {
  25. $finder = new Finder();
  26. $finder->ignoreDotFiles(false);
  27. $regex = Glob::toRegex('/**/*.neon');
  28. foreach ($finder->in(__DIR__) as $k => $v) {
  29. $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
  30. if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
  31. $match[] = substr($k, 10 + \strlen(__DIR__));
  32. }
  33. }
  34. sort($match);
  35. $this->assertSame(['one/b/c.neon', 'one/b/d.neon'], $match);
  36. }
  37. public function testGlobToRegexDoubleStarNonStrictDots()
  38. {
  39. $finder = new Finder();
  40. $finder->ignoreDotFiles(false);
  41. $regex = Glob::toRegex('/**/*.neon', false);
  42. foreach ($finder->in(__DIR__) as $k => $v) {
  43. $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
  44. if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
  45. $match[] = substr($k, 10 + \strlen(__DIR__));
  46. }
  47. }
  48. sort($match);
  49. $this->assertSame(['.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'], $match);
  50. }
  51. public function testGlobToRegexDoubleStarWithoutLeadingSlash()
  52. {
  53. $finder = new Finder();
  54. $finder->ignoreDotFiles(false);
  55. $regex = Glob::toRegex('/Fixtures/one/**');
  56. foreach ($finder->in(__DIR__) as $k => $v) {
  57. $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
  58. if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
  59. $match[] = substr($k, 10 + \strlen(__DIR__));
  60. }
  61. }
  62. sort($match);
  63. $this->assertSame(['one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
  64. }
  65. public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
  66. {
  67. $finder = new Finder();
  68. $finder->ignoreDotFiles(false);
  69. $regex = Glob::toRegex('/Fixtures/one/**', false);
  70. foreach ($finder->in(__DIR__) as $k => $v) {
  71. $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
  72. if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
  73. $match[] = substr($k, 10 + \strlen(__DIR__));
  74. }
  75. }
  76. sort($match);
  77. $this->assertSame(['one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
  78. }
  79. }