Task #104049
openCollisions in PSR-4 namespaces for tests
0%
Description
During the refactoring of the ViewHelper Schema Generator, I noticed that there are PSR-4 namespace collisions in the "Tests" folders of the core extensions. This usually isn't a problem if the classes are referenced by their correct namespace, but nontheless they are resolvable with another namespace. In that case, the file will be required twice, which leads to the following exception:
Fatal error: Cannot declare class TYPO3Tests\FluidTest\ViewHelpers\AbstractEscapingBaseViewHelper, because the name is already in use in /var/www/html/typo3/typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test/Classes/ViewHelpers/AbstractEscapingBaseViewHelper.php on line 22
The class in question is resolvable with the following namespaces:
TYPO3Tests\FluidTest\ViewHelpers\AbstractEscapingBaseViewHelper (the "correct" one)
TYPO3\CMS\Fluid\Tests\Functional\Fixtures\Extensions\fluid_test\Classes\ViewHelpers\AbstractEscapingBaseViewHelper
The source of the problem are the PSR-4 declarations in the root composer.json:
"autoload-dev": { "psr-4": { "TYPO3\\CMS\\Fluid\\Tests\\": "typo3/sysext/fluid/Tests/", "TYPO3Tests\\FluidTest\\": "typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test/Classes/",
We discussed this with Sebastian Bergmann of phpunit, and he suggested to get rid of the namespaces to the "Tests" folders altogether because they are not required for phpunit to find the tests. Only exception is if there are non-test classes in that folder (e. g. an abstract test class or a utility) that are used by other test classes. In that case, the individual file could be added to the classmap manually.