diff --git a/src/ClassMapGenerator.php b/src/ClassMapGenerator.php index 4e63236..52c3a82 100644 --- a/src/ClassMapGenerator.php +++ b/src/ClassMapGenerator.php @@ -218,10 +218,6 @@ private function filterByNamespace(array $classes, string $filePath, string $bas $realSubPath = substr($realSubPath, 0, $dotPosition === false ? PHP_INT_MAX : $dotPosition); foreach ($classes as $class) { - // silently skip if ns doesn't have common root - if ('' !== $baseNamespace && 0 !== strpos($class, $baseNamespace)) { - continue; - } // transform class name to file path and validate if ('psr-0' === $namespaceType) { $namespaceLength = strrpos($class, '\\'); diff --git a/tests/ClassMapGeneratorTest.php b/tests/ClassMapGeneratorTest.php index d671380..98d3094 100644 --- a/tests/ClassMapGeneratorTest.php +++ b/tests/ClassMapGeneratorTest.php @@ -240,6 +240,20 @@ public function testCreateMapDoesNotHitRegexBacktraceLimit(): void self::assertEqualsNormalized($expected, $result); } + public function testGetPSR4Violations(): void + { + $this->generator->scanPaths(__DIR__ . '/Fixtures/psrViolations', null, 'psr-4', 'ExpectedNamespace\\'); + $classMap = $this->generator->getClassMap(); + self::assertSame( + [ + 'Class ClassWithoutNameSpace located in ./tests/Fixtures/psrViolations/ClassWithoutNameSpace.php does not comply with psr-4 autoloading standard. Skipping.', + 'Class UnexpectedNamespace\ClassWithNameSpaceOutsideConfiguredScope located in ./tests/Fixtures/psrViolations/ClassWithNameSpaceOutsideConfiguredScope.php does not comply with psr-4 autoloading standard. Skipping.', + 'Class ExpectedNamespace\UnexpectedSubNamespace\ClassWithIncorrectSubNamespace located in ./tests/Fixtures/psrViolations/ClassWithIncorrectSubNamespace.php does not comply with psr-4 autoloading standard. Skipping.', + ], + $classMap->getPsrViolations() + ); + } + public function testCreateMapWithDirectoryExcluded(): void { $expected = array( diff --git a/tests/Fixtures/psrViolations/ClassWithCorrectNameSpace.php b/tests/Fixtures/psrViolations/ClassWithCorrectNameSpace.php new file mode 100644 index 0000000..3491cbb --- /dev/null +++ b/tests/Fixtures/psrViolations/ClassWithCorrectNameSpace.php @@ -0,0 +1,5 @@ +