diff --git a/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php b/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php index 591f6220e0bd1758760d7e4d70866e5533cab7ba..8e52155e3e13982cdeccb3fee98e4f8a6d04fd90 100644 --- a/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php +++ b/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php @@ -54,35 +54,152 @@ class ClassLoadingInformationGeneratorTest extends UnitTestCase { $generator = $this->getAccessibleMock( ClassLoadingInformationGenerator::class, ['dummy'], - [$this->getMock(ClassLoader::class), $this->createPackagesMock(), __DIR__] + [$this->getMock(ClassLoader::class), $this->createPackagesMock(array()), __DIR__] ); $this->assertEquals($expectedResult, $generator->_call('isIgnoredClassName', $className)); } + /** + * Data provider for different autoload information + * + * @return array + */ + public function autoloadFilesAreBuildCorrectlyDataProvider() { + return [ + 'Psr-4 section' => [ + [ + 'autoload' => [ + 'psr-4' => [ + 'TYPO3\\CMS\\TestExtension\\' => 'Classes/', + ], + ], + ], + [ + '\'TYPO3\\\\CMS\\\\TestExtension\\\\\' => array($typo3InstallDir . \'/Fixtures/test_extension/Classes\')', + ], + [], + ], + 'Psr-4 section without trailing slash' => [ + [ + 'autoload' => [ + 'psr-4' => [ + 'TYPO3\\CMS\\TestExtension\\' => 'Classes', + ], + ], + ], + [ + '\'TYPO3\\\\CMS\\\\TestExtension\\\\\' => array($typo3InstallDir . \'/Fixtures/test_extension/Classes\')', + ], + [], + ], + 'Classmap section' => [ + [ + 'autoload' => [ + 'classmap' => [ + 'Resources/PHP/', + ], + ], + ], + [], + [ + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php\'', + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php\'', + ], + ], + 'Classmap section without trailing slash' => [ + [ + 'autoload' => [ + 'classmap' => [ + 'Resources/PHP', + ], + ], + ], + [], + [ + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php\'', + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php\'', + ], + ], + 'Classmap section pointing to a file' => [ + [ + 'autoload' => [ + 'classmap' => [ + 'Resources/PHP/Test.php', + ], + ], + ], + [], + [ + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', + '!$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php\'', + '!$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php\'', + ], + ], + 'Classmap section pointing to two files' => [ + [ + 'autoload' => [ + 'classmap' => [ + 'Resources/PHP/Test.php', + 'Resources/PHP/AnotherTestFile.php', + ], + ], + ], + [], + [ + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', + '$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php\'', + '!$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php\'', + ], + ], + ]; + } + /** * @test + * @dataProvider autoloadFilesAreBuildCorrectlyDataProvider + * + * @param string $packageManifest + * @param array $expectedPsr4Files + * @param array $expectedClassMapFiles */ - public function autoloadFilesAreBuildCorrectly() { + public function autoloadFilesAreBuildCorrectly($packageManifest, $expectedPsr4Files, $expectedClassMapFiles) { /** @var ClassLoader|\PHPUnit_Framework_MockObject_MockObject $classLoaderMock */ $classLoaderMock = $this->getMock(ClassLoader::class); - $generator = new ClassLoadingInformationGenerator($classLoaderMock, $this->createPackagesMock(), __DIR__); + $generator = new ClassLoadingInformationGenerator($classLoaderMock, $this->createPackagesMock($packageManifest), __DIR__); $files = $generator->buildAutoloadInformationFiles(); $this->assertArrayHasKey('psr-4File', $files); $this->assertArrayHasKey('classMapFile', $files); - $this->assertContains('\'TYPO3\\\\CMS\\\\TestExtension\\\\\' => array($typo3InstallDir . \'/Fixtures/test_extension/Classes\')', $files['psr-4File']); - $this->assertContains('$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', $files['classMapFile']); + foreach ($expectedPsr4Files as $expectation) { + if ($expectation[0] === '!') { + $expectedCount = 0; + } else { + $expectedCount = 1; + } + $this->assertSame($expectedCount, substr_count($files['psr-4File'], $expectation)); + } + foreach ($expectedClassMapFiles as $expectation) { + if ($expectation[0] === '!') { + $expectedCount = 0; + } else { + $expectedCount = 1; + } + $this->assertSame($expectedCount, substr_count($files['classMapFile'], $expectation)); + } } /** + * @param array Array which should be returned as composer manifest * @return PackageInterface[] */ - protected function createPackagesMock() { + protected function createPackagesMock($packageManifest) { $packageStub = $this->getMock(PackageInterface::class); $packageStub->expects($this->any())->method('getPackagePath')->willReturn(__DIR__ . '/Fixtures/test_extension/'); $packageStub->expects($this->any())->method('getValueFromComposerManifest')->willReturn( - json_decode(file_get_contents(__DIR__ . '/Fixtures/test_extension/composer.json')) + json_decode(json_encode($packageManifest)) ); return [$packageStub]; diff --git a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php new file mode 100644 index 0000000000000000000000000000000000000000..a080adf77da8a68263c75417d4c233640db17f84 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/AnotherTestFile.php @@ -0,0 +1,19 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Core\Fixtures\test_extension\Resources\PHP; + +/* * + * This script belongs to the TYPO3 Flow framework. * + * * + * It is free software; you can redistribute it and/or modify it under * + * the terms of the GNU Lesser General Public License, either version 3 * + * of the License, or (at your option) any later version. * + * * + * The TYPO3 project - inspiring people to share! * + * */ + +/** + * Class Test + */ +class AnotherTestFile { + +} \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php new file mode 100644 index 0000000000000000000000000000000000000000..82fb3e6caf6f0c4e7e61e3f5c053d58abd32d5ab --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/Resources/PHP/Subdirectory/SubdirectoryTest.php @@ -0,0 +1,19 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Core\Fixtures\test_extension\Resources\PHP\Subdirectory; + +/* * + * This script belongs to the TYPO3 Flow framework. * + * * + * It is free software; you can redistribute it and/or modify it under * + * the terms of the GNU Lesser General Public License, either version 3 * + * of the License, or (at your option) any later version. * + * * + * The TYPO3 project - inspiring people to share! * + * */ + +/** + * Class Test + */ +class SubdirectoryTest { + +} \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json deleted file mode 100644 index 215103bef4748532ad54de10e7599415efa46aa8..0000000000000000000000000000000000000000 --- a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "typo3/cms-core-test", - "type": "typo3-cms-extension", - "description": "TYPO3 Core Test", - "homepage": "https://typo3.org", - "license": ["GPL-2.0+"], - - "require": { - "php" : ">=5.5.0" - }, - "replace": { - "core": "*" - }, - "autoload": { - "psr-4": { - "TYPO3\\CMS\\TestExtension\\": "Classes/" - }, - "classmap": ["Resources/PHP/Test.php"] - } -} diff --git a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/ext_emconf.php b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/ext_emconf.php deleted file mode 100644 index 29fcff4352020c5a43e5979d47390605bff0afd6..0000000000000000000000000000000000000000 --- a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/ext_emconf.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -$EM_CONF[$_EXTKEY] = array( - 'title' => 'TYPO3 Core Test', - 'description' => 'Test Extension', - 'category' => 'be', - 'state' => 'stable', - 'uploadfolder' => 0, - 'createDirs' => '', - 'clearCacheOnLoad' => 0, - 'author' => 'Helmut Hummel', - 'author_email' => 'helmut@typo3.org', - 'author_company' => '', - 'version' => '7.6.0', - 'constraints' => array( - 'depends' => array(), - 'conflicts' => array(), - 'suggests' => array(), - ), -);