Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Finder\Tests; Chris@0: Chris@0: use PHPUnit\Framework\TestCase; Chris@0: use Symfony\Component\Finder\Finder; Chris@0: use Symfony\Component\Finder\Glob; Chris@0: Chris@0: class GlobTest extends TestCase Chris@0: { Chris@0: public function testGlobToRegexDelimiters() Chris@0: { Chris@0: $this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#')); Chris@0: $this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*')); Chris@0: $this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, '')); Chris@0: $this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/')); Chris@0: } Chris@0: Chris@0: public function testGlobToRegexDoubleStarStrictDots() Chris@0: { Chris@0: $finder = new Finder(); Chris@0: $finder->ignoreDotFiles(false); Chris@0: $regex = Glob::toRegex('/**/*.neon'); Chris@0: Chris@0: foreach ($finder->in(__DIR__) as $k => $v) { Chris@17: $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k); Chris@17: if (preg_match($regex, substr($k, \strlen(__DIR__)))) { Chris@17: $match[] = substr($k, 10 + \strlen(__DIR__)); Chris@0: } Chris@0: } Chris@0: sort($match); Chris@0: Chris@17: $this->assertSame(['one/b/c.neon', 'one/b/d.neon'], $match); Chris@0: } Chris@0: Chris@0: public function testGlobToRegexDoubleStarNonStrictDots() Chris@0: { Chris@0: $finder = new Finder(); Chris@0: $finder->ignoreDotFiles(false); Chris@0: $regex = Glob::toRegex('/**/*.neon', false); Chris@0: Chris@0: foreach ($finder->in(__DIR__) as $k => $v) { Chris@17: $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k); Chris@17: if (preg_match($regex, substr($k, \strlen(__DIR__)))) { Chris@17: $match[] = substr($k, 10 + \strlen(__DIR__)); Chris@0: } Chris@0: } Chris@0: sort($match); Chris@0: Chris@17: $this->assertSame(['.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'], $match); Chris@0: } Chris@0: Chris@0: public function testGlobToRegexDoubleStarWithoutLeadingSlash() Chris@0: { Chris@0: $finder = new Finder(); Chris@0: $finder->ignoreDotFiles(false); Chris@0: $regex = Glob::toRegex('/Fixtures/one/**'); Chris@0: Chris@0: foreach ($finder->in(__DIR__) as $k => $v) { Chris@17: $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k); Chris@17: if (preg_match($regex, substr($k, \strlen(__DIR__)))) { Chris@17: $match[] = substr($k, 10 + \strlen(__DIR__)); Chris@0: } Chris@0: } Chris@0: sort($match); Chris@0: Chris@17: $this->assertSame(['one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match); Chris@0: } Chris@0: Chris@0: public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot() Chris@0: { Chris@0: $finder = new Finder(); Chris@0: $finder->ignoreDotFiles(false); Chris@0: $regex = Glob::toRegex('/Fixtures/one/**', false); Chris@0: Chris@0: foreach ($finder->in(__DIR__) as $k => $v) { Chris@17: $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k); Chris@17: if (preg_match($regex, substr($k, \strlen(__DIR__)))) { Chris@17: $match[] = substr($k, 10 + \strlen(__DIR__)); Chris@0: } Chris@0: } Chris@0: sort($match); Chris@0: Chris@17: $this->assertSame(['one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match); Chris@0: } Chris@0: }