Skip to content

Commit fd0a3b6

Browse files
authored
Merge pull request #8868 from kenjis/fix-FileCollection-pseudo-regex
fix: FileCollection pseudo-regex
2 parents f03602f + 7eb7604 commit fd0a3b6

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

system/Files/FileCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ final protected static function matchFiles(array $files, string $pattern): array
105105
['\#', '\.', '.*', '.'],
106106
$pattern
107107
);
108-
$pattern = "#{$pattern}#";
108+
$pattern = "#\\A{$pattern}\\z#";
109109
}
110110

111111
return array_filter($files, static fn ($value) => (bool) preg_match($pattern, basename($value)));

tests/_support/Files/baker/fig_3.php.txt

Whitespace-only changes.

tests/system/Files/FileCollectionTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function testAddStringDirectoryRecursive(): void
175175
$this->directory . 'fig_3.php',
176176
$this->directory . 'prune_ripe.php',
177177
SUPPORTPATH . 'Files/baker/banana.php',
178+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
178179
];
179180

180181
$files->add(SUPPORTPATH . 'Files');
@@ -227,6 +228,7 @@ public function testAddArrayRecursive(): void
227228
$this->directory . 'fig_3.php',
228229
$this->directory . 'prune_ripe.php',
229230
SUPPORTPATH . 'Files/baker/banana.php',
231+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
230232
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
231233
];
232234

@@ -392,6 +394,7 @@ public function testAddDirectoryRecursive(): void
392394
$this->directory . 'fig_3.php',
393395
$this->directory . 'prune_ripe.php',
394396
SUPPORTPATH . 'Files/baker/banana.php',
397+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
395398
];
396399

397400
$collection->addDirectory(SUPPORTPATH . 'Files', true);
@@ -407,6 +410,7 @@ public function testAddDirectories(): void
407410
$this->directory . 'fig_3.php',
408411
$this->directory . 'prune_ripe.php',
409412
SUPPORTPATH . 'Files/baker/banana.php',
413+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
410414
];
411415

412416
$collection->addDirectories([
@@ -425,6 +429,7 @@ public function testAddDirectoriesRecursive(): void
425429
$this->directory . 'fig_3.php',
426430
$this->directory . 'prune_ripe.php',
427431
SUPPORTPATH . 'Files/baker/banana.php',
432+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
428433
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
429434
];
430435

@@ -471,6 +476,7 @@ public function testRemovePatternPseudo(): void
471476
$expected = [
472477
$this->directory . 'apple.php',
473478
SUPPORTPATH . 'Files/baker/banana.php',
479+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
474480
];
475481

476482
$collection->removePattern('*_*.php');
@@ -485,6 +491,7 @@ public function testRemovePatternScope(): void
485491

486492
$expected = [
487493
SUPPORTPATH . 'Files/baker/banana.php',
494+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
488495
];
489496

490497
$collection->removePattern('*.php', $this->directory);
@@ -512,6 +519,7 @@ public function testRetainPatternRegex(): void
512519
$expected = [
513520
$this->directory . 'fig_3.php',
514521
$this->directory . 'prune_ripe.php',
522+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
515523
];
516524

517525
$collection->retainPattern('#[a-z]+_.*#');
@@ -541,6 +549,7 @@ public function testRetainPatternScope(): void
541549
$expected = [
542550
$this->directory . 'fig_3.php',
543551
SUPPORTPATH . 'Files/baker/banana.php',
552+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
544553
];
545554

546555
$collection->retainPattern('*_?.php', $this->directory);
@@ -553,7 +562,7 @@ public function testCount(): void
553562
$collection = new FileCollection();
554563
$collection->addDirectory(SUPPORTPATH . 'Files', true);
555564

556-
$this->assertCount(4, $collection);
565+
$this->assertCount(5, $collection);
557566
}
558567

559568
public function testIterable(): void
@@ -568,6 +577,6 @@ public function testIterable(): void
568577
$count++;
569578
}
570579

571-
$this->assertSame($count, 4);
580+
$this->assertSame($count, 5);
572581
}
573582
}

tests/system/Helpers/FilesystemHelperTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,20 +429,32 @@ public function testGetFilenamesWithSymlinks(): void
429429

430430
public function testGetDirFileInfo(): void
431431
{
432-
$file = SUPPORTPATH . 'Files/baker/banana.php';
433-
$info = get_file_info($file);
432+
$file1 = SUPPORTPATH . 'Files/baker/banana.php';
433+
$info1 = get_file_info($file1);
434+
$file2 = SUPPORTPATH . 'Files/baker/fig_3.php.txt';
435+
$info2 = get_file_info($file2);
434436

435437
$expected = [
436438
'banana.php' => [
437439
'name' => 'banana.php',
438-
'server_path' => $file,
439-
'size' => $info['size'],
440-
'date' => $info['date'],
440+
'server_path' => $file1,
441+
'size' => $info1['size'],
442+
'date' => $info1['date'],
443+
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
444+
],
445+
'fig_3.php.txt' => [
446+
'name' => 'fig_3.php.txt',
447+
'server_path' => $file2,
448+
'size' => $info2['size'],
449+
'date' => $info2['date'],
441450
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
442451
],
443452
];
444453

445-
$this->assertSame($expected, get_dir_file_info(SUPPORTPATH . 'Files/baker'));
454+
$result = get_dir_file_info(SUPPORTPATH . 'Files/baker');
455+
ksort($result);
456+
457+
$this->assertSame($expected, $result);
446458
}
447459

448460
public function testGetDirFileInfoNested(): void

tests/system/Publisher/PublisherInputTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function testAddPathDirectoryRecursive(): void
8686
$this->directory . 'fig_3.php',
8787
$this->directory . 'prune_ripe.php',
8888
SUPPORTPATH . 'Files/baker/banana.php',
89+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
8990
];
9091

9192
$publisher->addPath('Files');
@@ -121,6 +122,7 @@ public function testAddPathsRecursive(): void
121122
$this->directory . 'fig_3.php',
122123
$this->directory . 'prune_ripe.php',
123124
SUPPORTPATH . 'Files/baker/banana.php',
125+
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
124126
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
125127
];
126128

tests/system/Publisher/PublisherOutputTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public function testMerge(): void
161161
$this->root->url() . '/able/fig_3.php',
162162
$this->root->url() . '/able/prune_ripe.php',
163163
$this->root->url() . '/baker/banana.php',
164+
$this->root->url() . '/baker/fig_3.php.txt',
164165
];
165166

166167
$this->assertFileDoesNotExist($this->root->url() . '/able/fig_3.php');
@@ -183,6 +184,7 @@ public function testMergeReplace(): void
183184
$this->root->url() . '/able/fig_3.php',
184185
$this->root->url() . '/able/prune_ripe.php',
185186
$this->root->url() . '/baker/banana.php',
187+
$this->root->url() . '/baker/fig_3.php.txt',
186188
];
187189

188190
$result = $publisher->addPath('/')->merge(true);
@@ -200,6 +202,7 @@ public function testMergeCollides(): void
200202
$this->root->url() . '/able/apple.php',
201203
$this->root->url() . '/able/prune_ripe.php',
202204
$this->root->url() . '/baker/banana.php',
205+
$this->root->url() . '/baker/fig_3.php.txt',
203206
];
204207

205208
mkdir($this->root->url() . '/able/fig_3.php');

0 commit comments

Comments
 (0)