4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Finder;
16 use Symfony\Component\Finder\Glob;
18 class GlobTest extends TestCase
20 public function testGlobToRegexDelimiters()
22 $this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#'));
23 $this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*'));
24 $this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, ''));
25 $this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/'));
28 public function testGlobToRegexDoubleStarStrictDots()
30 $finder = new Finder();
31 $finder->ignoreDotFiles(false);
32 $regex = Glob::toRegex('/**/*.neon');
34 foreach ($finder->in(__DIR__) as $k => $v) {
35 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
36 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
37 $match[] = substr($k, 10 + \strlen(__DIR__));
42 $this->assertSame(array('one/b/c.neon', 'one/b/d.neon'), $match);
45 public function testGlobToRegexDoubleStarNonStrictDots()
47 $finder = new Finder();
48 $finder->ignoreDotFiles(false);
49 $regex = Glob::toRegex('/**/*.neon', false);
51 foreach ($finder->in(__DIR__) as $k => $v) {
52 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
53 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
54 $match[] = substr($k, 10 + \strlen(__DIR__));
59 $this->assertSame(array('.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'), $match);
62 public function testGlobToRegexDoubleStarWithoutLeadingSlash()
64 $finder = new Finder();
65 $finder->ignoreDotFiles(false);
66 $regex = Glob::toRegex('/Fixtures/one/**');
68 foreach ($finder->in(__DIR__) as $k => $v) {
69 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
70 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
71 $match[] = substr($k, 10 + \strlen(__DIR__));
76 $this->assertSame(array('one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);
79 public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
81 $finder = new Finder();
82 $finder->ignoreDotFiles(false);
83 $regex = Glob::toRegex('/Fixtures/one/**', false);
85 foreach ($finder->in(__DIR__) as $k => $v) {
86 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
87 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
88 $match[] = substr($k, 10 + \strlen(__DIR__));
93 $this->assertSame(array('one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);