Skip to content

Commit 57d39ce

Browse files
author
Pieter Zandbergen
committed
fix: Added unit test
1 parent df81d6b commit 57d39ce

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Test\Unit\Filesystem;
9+
10+
use Magento\Framework\Filesystem\Glob;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class GlobTest extends TestCase
14+
{
15+
public function testClearCache(): void
16+
{
17+
$dir = __DIR__ . '/_files/glob';
18+
$pattern = $dir . '/*.txt';
19+
$testFile = $dir . '/c.txt';
20+
try {
21+
if (is_file($testFile)) {
22+
unlink($testFile);
23+
}
24+
$this->assert(['a.txt', 'b.txt'], Glob::glob($pattern));
25+
touch($testFile);
26+
$this->assert(['a.txt', 'b.txt'], Glob::glob($pattern));
27+
Glob::clearCache();
28+
$this->assert(['a.txt', 'b.txt', 'c.txt'], Glob::glob($pattern));
29+
} finally {
30+
if (is_file($testFile)) {
31+
unlink($testFile);
32+
}
33+
}
34+
}
35+
36+
private function assert(array $expected, array $results): void
37+
{
38+
$results = array_map(static function (string $file): string {
39+
return substr($file, strrpos($file, '/') + 1);
40+
}, $results);
41+
$missing = array_diff($expected, $results);
42+
$this->assertEmpty($missing, 'Missing files: ' . implode(', ', $missing));
43+
$unexpected = array_diff($results, $expected);
44+
$this->assertEmpty($unexpected, 'Unexpected files: ' . implode(', ', $unexpected));
45+
}
46+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Text file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Text file

0 commit comments

Comments
 (0)