Skip to content

Commit 5f7d226

Browse files
authored
TestsExcluder not to exclude mixed usages in tests (#214)
1 parent 86f3d64 commit 5f7d226

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/Excluder/TestsUsageExcluder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function shouldExclude(ClassMemberUsage $usage, Node $node, Scope $scope)
6868
return false;
6969
}
7070

71-
return $this->isWithinDevPaths($this->realpath($scope->getFile()))
72-
&& !$this->isWithinDevPaths($this->getDeclarationFile($usage->getMemberRef()->getClassName()));
71+
return $this->isWithinDevPaths($this->realpath($scope->getFile())) === true
72+
&& $this->isWithinDevPaths($this->getDeclarationFile($usage->getMemberRef()->getClassName())) === false;
7373
}
7474

75-
private function isWithinDevPaths(?string $filePath): bool
75+
private function isWithinDevPaths(?string $filePath): ?bool
7676
{
7777
if ($filePath === null) {
78-
return false;
78+
return null;
7979
}
8080

8181
foreach ($this->devPaths as $devPath) {

tests/Rule/data/excluders/tests/src/code.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class DeclaredInSrcUsedInTests {
44
const CONST = 1; // error: Unused DeclaredInSrcUsedInTests::CONST (all usages excluded by tests excluder)
5+
const MIXED = 2;
56
}
67

78
class DeclaredInSrcUsedInBoth {

tests/Rule/data/excluders/tests/tests/code.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class DeclaredInTestsUsedInSrc {
1212
const CONST = 1;
1313
}
1414

15-
function test1() {
15+
function test1($mixed) {
1616
echo DeclaredInSrcUsedInBoth::CONST;
1717
echo DeclaredInSrcUsedInTests::CONST;
1818
echo DeclaredInTestsUsedInTests::CONST;
1919
echo DeclaredInTestsUsedInBoth::CONST;
20+
$mixed::MIXED;
2021
}

0 commit comments

Comments
 (0)