Skip to content

Commit 502ce58

Browse files
committed
Add test for trailing slash
1 parent 5131c42 commit 502ce58

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

src/TextUI/Configuration/README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
(this file can be removed before merging)
2+
13
SourceMapper Implementation Notes
24
=================================
35

4-
Currently the `<directory>` element in `<include>` and `<exclude>` has the
5-
attributes `prefix` and `suffix` and we also have `<file>` which specifies a
6-
single file.
7-
8-
Our primary goal is to ensure that the source mapper needn't iterate over all
6+
The primary goal is to ensure that the source mapper needn't iterate over all
97
included files recursively whenever the source map is required (for example
108
when a deprecation is encountered PHPUnit needs to know if the deprecation was
119
issued from source code within the project's responsiblity - i.e. source that
1210
is mapped). We can determine if a file is within the included source by
1311
converting the glob-patterns in the `<directory>` element to regexes.
1412

15-
This is more complicated than it could be as the current matching logic
16-
depends on PHP's `glob` function - the implementation of which is not
17-
consistent across platforms and which has a number of rarely-used operators
18-
which while not common, would present a B/C break if they were removed.
13+
Currently the `<directory>` element in `<include>` and `<exclude>` has the
14+
attributes `prefix` and `suffix` and we also have `<file>` which specifies a
15+
single file.
16+
17+
This is more complicated than it could be:
18+
19+
- Current matching/traversal logic depends on PHP's `glob` function - the implementation
20+
of which is not consistent across platforms and which has a number of
21+
rarely-used operators which while not common, would present a B/C break if
22+
they were removed.
23+
24+
25+
26+
1927

2028
How it works currently
2129
----------------------
@@ -44,6 +52,8 @@ The Factory:
4452
- create a new PHPUnit `Iterator` passing a recursive iterator iterator
4553
directory iterator... (the iterator that iterates over the directories) that
4654
**follows symlinks and skips dots**.
55+
- the iterator also Excludes the excluded `<directory>` elements **but does
56+
not take into account the prefixes or suffixes**.
4757

4858
The Iterator:
4959

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: 24 additions & 12 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,
@@ -167,18 +179,18 @@ public static function provider(): array
167179
),
168180
),
169181
],
170-
//'directory wildcard does not include files at same level' => [
171-
// [
172-
// self::fixturePath('a/PrefixSuffix.php') => false,
173-
// ],
174-
// self::createSource(
175-
// includeDirectories: FilterDirectoryCollection::fromArray(
176-
// [
177-
// new FilterDirectory(self::fixturePath(), 'a/*', '.php'),
178-
// ],
179-
// ),
180-
// ),
181-
//],
182+
'directory wildcard does not include files at same level' => [
183+
[
184+
self::fixturePath('a/PrefixSuffix.php') => false,
185+
],
186+
self::createSource(
187+
includeDirectories: FilterDirectoryCollection::fromArray(
188+
[
189+
new FilterDirectory(self::fixturePath(), 'a/*', '.php'),
190+
],
191+
),
192+
),
193+
],
182194
'directory wildcard with suffix does not match files' => [
183195
[
184196
self::fixturePath('a/PrefixSuffix.php') => false,

0 commit comments

Comments
 (0)