Skip to content
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 src/Symfony/Component/Config/Resource/GlobResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getIterator(): \Traversable
if (class_exists(Finder::class)) {
$regex = Glob::toRegex($pattern);
if ($this->recursive) {
$regex = substr_replace($regex, '(/|$)', -2, 1);
$regex = substr_replace($regex, str_ends_with($pattern, '/') ? '' : '(/|$)', -2, 1);
}
} else {
$regex = null;
Expand Down
18 changes: 7 additions & 11 deletions src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ protected function tearDown(): void
touch($dir.'/Resource/.hiddenFile');
}

public function testIterator()
/**
* @testWith ["/Resource"]
* ["/**\/Resource"]
* ["/**\/Resource/"]
*/
public function testIterator(string $pattern)
{
$dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
$resource = new GlobResource($dir, '/Resource', true);
$resource = new GlobResource($dir, $pattern, true);

$paths = iterator_to_array($resource);

$file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
$this->assertEquals([$file => new \SplFileInfo($file)], $paths);
$this->assertInstanceOf(\SplFileInfo::class, current($paths));
$this->assertSame($dir, $resource->getPrefix());

$resource = new GlobResource($dir, '/**/Resource', true);

$paths = iterator_to_array($resource);

$file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
$this->assertEquals([$file => $file], $paths);
$this->assertInstanceOf(\SplFileInfo::class, current($paths));
$this->assertSame($dir, $resource->getPrefix());
}

public function testIteratorForExclusionDoesntIterateThroughSubfolders()
Expand Down
Loading