Skip to content

Commit 5b4a247

Browse files
Merge remote-tracking branch '38394/patch-4' into novcomprs
2 parents d2fd820 + f8906f3 commit 5b4a247

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

lib/internal/Magento/Framework/Filesystem/Glob.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Framework\Filesystem;
@@ -19,6 +19,19 @@ class Glob extends LaminasGlob
1919
*/
2020
private static $cache = [];
2121

22+
/**
23+
* Clear the static cache for glob patterns.
24+
* This method should be used primarily in testing environments
25+
* or long-running processes where file system changes occur
26+
* between glob() calls and fresh results are required.
27+
*
28+
* @return void
29+
*/
30+
public static function clearCache(): void
31+
{
32+
self::$cache = [];
33+
}
34+
2235
/**
2336
* Find path names matching a pattern.
2437
*
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)