comparison vendor/symfony/finder/Tests/GlobTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
30 $finder = new Finder(); 30 $finder = new Finder();
31 $finder->ignoreDotFiles(false); 31 $finder->ignoreDotFiles(false);
32 $regex = Glob::toRegex('/**/*.neon'); 32 $regex = Glob::toRegex('/**/*.neon');
33 33
34 foreach ($finder->in(__DIR__) as $k => $v) { 34 foreach ($finder->in(__DIR__) as $k => $v) {
35 $k = str_replace(DIRECTORY_SEPARATOR, '/', $k); 35 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
36 if (preg_match($regex, substr($k, strlen(__DIR__)))) { 36 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
37 $match[] = substr($k, 10 + strlen(__DIR__)); 37 $match[] = substr($k, 10 + \strlen(__DIR__));
38 } 38 }
39 } 39 }
40 sort($match); 40 sort($match);
41 41
42 $this->assertSame(array('one/b/c.neon', 'one/b/d.neon'), $match); 42 $this->assertSame(['one/b/c.neon', 'one/b/d.neon'], $match);
43 } 43 }
44 44
45 public function testGlobToRegexDoubleStarNonStrictDots() 45 public function testGlobToRegexDoubleStarNonStrictDots()
46 { 46 {
47 $finder = new Finder(); 47 $finder = new Finder();
48 $finder->ignoreDotFiles(false); 48 $finder->ignoreDotFiles(false);
49 $regex = Glob::toRegex('/**/*.neon', false); 49 $regex = Glob::toRegex('/**/*.neon', false);
50 50
51 foreach ($finder->in(__DIR__) as $k => $v) { 51 foreach ($finder->in(__DIR__) as $k => $v) {
52 $k = str_replace(DIRECTORY_SEPARATOR, '/', $k); 52 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
53 if (preg_match($regex, substr($k, strlen(__DIR__)))) { 53 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
54 $match[] = substr($k, 10 + strlen(__DIR__)); 54 $match[] = substr($k, 10 + \strlen(__DIR__));
55 } 55 }
56 } 56 }
57 sort($match); 57 sort($match);
58 58
59 $this->assertSame(array('.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'), $match); 59 $this->assertSame(['.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'], $match);
60 } 60 }
61 61
62 public function testGlobToRegexDoubleStarWithoutLeadingSlash() 62 public function testGlobToRegexDoubleStarWithoutLeadingSlash()
63 { 63 {
64 $finder = new Finder(); 64 $finder = new Finder();
65 $finder->ignoreDotFiles(false); 65 $finder->ignoreDotFiles(false);
66 $regex = Glob::toRegex('/Fixtures/one/**'); 66 $regex = Glob::toRegex('/Fixtures/one/**');
67 67
68 foreach ($finder->in(__DIR__) as $k => $v) { 68 foreach ($finder->in(__DIR__) as $k => $v) {
69 $k = str_replace(DIRECTORY_SEPARATOR, '/', $k); 69 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
70 if (preg_match($regex, substr($k, strlen(__DIR__)))) { 70 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
71 $match[] = substr($k, 10 + strlen(__DIR__)); 71 $match[] = substr($k, 10 + \strlen(__DIR__));
72 } 72 }
73 } 73 }
74 sort($match); 74 sort($match);
75 75
76 $this->assertSame(array('one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match); 76 $this->assertSame(['one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
77 } 77 }
78 78
79 public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot() 79 public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
80 { 80 {
81 $finder = new Finder(); 81 $finder = new Finder();
82 $finder->ignoreDotFiles(false); 82 $finder->ignoreDotFiles(false);
83 $regex = Glob::toRegex('/Fixtures/one/**', false); 83 $regex = Glob::toRegex('/Fixtures/one/**', false);
84 84
85 foreach ($finder->in(__DIR__) as $k => $v) { 85 foreach ($finder->in(__DIR__) as $k => $v) {
86 $k = str_replace(DIRECTORY_SEPARATOR, '/', $k); 86 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
87 if (preg_match($regex, substr($k, strlen(__DIR__)))) { 87 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
88 $match[] = substr($k, 10 + strlen(__DIR__)); 88 $match[] = substr($k, 10 + \strlen(__DIR__));
89 } 89 }
90 } 90 }
91 sort($match); 91 sort($match);
92 92
93 $this->assertSame(array('one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match); 93 $this->assertSame(['one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
94 } 94 }
95 } 95 }