Skip to content
Snippets Groups Projects
Commit 9981dcc9 authored by Nicole Cordes's avatar Nicole Cordes Committed by Wouter Wolters
Browse files

[TASK] Adjust tests for ClassLoadingInformationGenerator

This patch covers multiple testing scenarios to ensure the generator
class works properly with different user input.

Resolves: #70253
Releases: master
Change-Id: I1c6ab42caffc26bd544625a6bb6092988d99d6c4
Reviewed-on: http://review.typo3.org/43686


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
parent e64fd69b
Branches
Tags
No related merge requests found
......@@ -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];
......
<?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
<?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
{
"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"]
}
}
<?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(),
),
);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment