Skip to content

Commit e6c0737

Browse files
committed
Add test for trailing slash
1 parent f0d59b5 commit e6c0737

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/TextUI/Configuration/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ The Factory:
4444
- create a new PHPUnit `Iterator` passing a recursive iterator iterator
4545
directory iterator... (the iterator that iterates over the directories) that
4646
**follows symlinks and skips dots**.
47+
- the iterator also Excludes the excluded `<directory>` elements **but does
48+
not take into account the prefixes or suffixes**.
4749

4850
The Iterator:
4951

src/TextUI/Configuration/SourceFilter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(Source $source)
6363
public function includes(string $path): bool
6464
{
6565
$included = false;
66-
$dirPath = dirname($path) . '/';
66+
$dirPath = rtrim(dirname($path), '/') . '/';
6767
$filename = basename($path);
6868
foreach ($this->source->includeFiles() as $file) {
6969
if ($file->path() === $path) {
@@ -100,12 +100,12 @@ public function includes(string $path): bool
100100
*/
101101
public static function toGlob(FilterDirectory $directory): string
102102
{
103-
$path = $directory->path();
103+
$path = rtrim($directory->path(), '/');
104104

105105
return sprintf(
106106
'{(%s)|(%s)}',
107-
Glob::toRegEx(sprintf('%s/**/*', $directory->path()), 0, ''),
108-
Glob::toRegEx(sprintf('%s/*', $directory->path()), 0, ''),
107+
Glob::toRegEx(sprintf('%s/**/*', $path), 0, ''),
108+
Glob::toRegEx(sprintf('%s/*', $path), 0, ''),
109109
);
110110
}
111111

tests/unit/TextUI/SourceFilterTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public static function provider(): array
8080
),
8181
),
8282
],
83+
'file included using directory with trailing slash' => [
84+
[
85+
self::fixturePath('a/PrefixSuffix.php') => true,
86+
],
87+
self::createSource(
88+
includeDirectories: FilterDirectoryCollection::fromArray(
89+
[
90+
new FilterDirectory(self::fixturePath() . '/', '', '.php'),
91+
],
92+
),
93+
),
94+
],
8395
'file included using directory, but excluded using file' => [
8496
[
8597
self::fixturePath('a/PrefixSuffix.php') => false,

0 commit comments

Comments
 (0)