Skip to content

fix: FileCollection pseudo-regex #8868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Files/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final protected static function matchFiles(array $files, string $pattern): array
['\#', '\.', '.*', '.'],
$pattern
);
$pattern = "#{$pattern}#";
$pattern = "#\\A{$pattern}\\z#";
}

return array_filter($files, static fn ($value) => (bool) preg_match($pattern, basename($value)));
Expand Down
Empty file.
13 changes: 11 additions & 2 deletions tests/system/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function testAddStringDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$files->add(SUPPORTPATH . 'Files');
Expand Down Expand Up @@ -227,6 +228,7 @@ public function testAddArrayRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down Expand Up @@ -392,6 +394,7 @@ public function testAddDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->addDirectory(SUPPORTPATH . 'Files', true);
Expand All @@ -407,6 +410,7 @@ public function testAddDirectories(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->addDirectories([
Expand All @@ -425,6 +429,7 @@ public function testAddDirectoriesRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down Expand Up @@ -471,6 +476,7 @@ public function testRemovePatternPseudo(): void
$expected = [
$this->directory . 'apple.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

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

$expected = [
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->removePattern('*.php', $this->directory);
Expand Down Expand Up @@ -512,6 +519,7 @@ public function testRetainPatternRegex(): void
$expected = [
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

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

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

$this->assertCount(4, $collection);
$this->assertCount(5, $collection);
}

public function testIterable(): void
Expand All @@ -568,6 +577,6 @@ public function testIterable(): void
$count++;
}

$this->assertSame($count, 4);
$this->assertSame($count, 5);
}
}
24 changes: 18 additions & 6 deletions tests/system/Helpers/FilesystemHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,32 @@ public function testGetFilenamesWithSymlinks(): void

public function testGetDirFileInfo(): void
{
$file = SUPPORTPATH . 'Files/baker/banana.php';
$info = get_file_info($file);
$file1 = SUPPORTPATH . 'Files/baker/banana.php';
$info1 = get_file_info($file1);
$file2 = SUPPORTPATH . 'Files/baker/fig_3.php.txt';
$info2 = get_file_info($file2);

$expected = [
'banana.php' => [
'name' => 'banana.php',
'server_path' => $file,
'size' => $info['size'],
'date' => $info['date'],
'server_path' => $file1,
'size' => $info1['size'],
'date' => $info1['date'],
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
],
'fig_3.php.txt' => [
'name' => 'fig_3.php.txt',
'server_path' => $file2,
'size' => $info2['size'],
'date' => $info2['date'],
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
],
];

$this->assertSame($expected, get_dir_file_info(SUPPORTPATH . 'Files/baker'));
$result = get_dir_file_info(SUPPORTPATH . 'Files/baker');
ksort($result);

$this->assertSame($expected, $result);
}

public function testGetDirFileInfoNested(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/system/Publisher/PublisherInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function testAddPathDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$publisher->addPath('Files');
Expand Down Expand Up @@ -121,6 +122,7 @@ public function testAddPathsRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down
3 changes: 3 additions & 0 deletions tests/system/Publisher/PublisherOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function testMerge(): void
$this->root->url() . '/able/fig_3.php',
$this->root->url() . '/able/prune_ripe.php',
$this->root->url() . '/baker/banana.php',
$this->root->url() . '/baker/fig_3.php.txt',
];

$this->assertFileDoesNotExist($this->root->url() . '/able/fig_3.php');
Expand All @@ -183,6 +184,7 @@ public function testMergeReplace(): void
$this->root->url() . '/able/fig_3.php',
$this->root->url() . '/able/prune_ripe.php',
$this->root->url() . '/baker/banana.php',
$this->root->url() . '/baker/fig_3.php.txt',
];

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

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