comparison vendor/symfony/finder/Tests/GlobTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Finder\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Finder;
16 use Symfony\Component\Finder\Glob;
17
18 class GlobTest extends TestCase
19 {
20 public function testGlobToRegexDelimiters()
21 {
22 $this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#'));
23 $this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*'));
24 $this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, ''));
25 $this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/'));
26 }
27
28 public function testGlobToRegexDoubleStarStrictDots()
29 {
30 $finder = new Finder();
31 $finder->ignoreDotFiles(false);
32 $regex = Glob::toRegex('/**/*.neon');
33
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__));
38 }
39 }
40 sort($match);
41
42 $this->assertSame(array('one/b/c.neon', 'one/b/d.neon'), $match);
43 }
44
45 public function testGlobToRegexDoubleStarNonStrictDots()
46 {
47 $finder = new Finder();
48 $finder->ignoreDotFiles(false);
49 $regex = Glob::toRegex('/**/*.neon', false);
50
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__));
55 }
56 }
57 sort($match);
58
59 $this->assertSame(array('.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'), $match);
60 }
61
62 public function testGlobToRegexDoubleStarWithoutLeadingSlash()
63 {
64 $finder = new Finder();
65 $finder->ignoreDotFiles(false);
66 $regex = Glob::toRegex('/Fixtures/one/**');
67
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__));
72 }
73 }
74 sort($match);
75
76 $this->assertSame(array('one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);
77 }
78
79 public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
80 {
81 $finder = new Finder();
82 $finder->ignoreDotFiles(false);
83 $regex = Glob::toRegex('/Fixtures/one/**', false);
84
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__));
89 }
90 }
91 sort($match);
92
93 $this->assertSame(array('one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);
94 }
95 }