TASK: Improve tests and fix issues
* Configure code coverage for new tested class. * Fix usage of class with new insensitivity lookup. * Add further tests.
This commit is contained in:
parent
666bbdb26a
commit
b69c262288
5 changed files with 78 additions and 30 deletions
|
@ -5,6 +5,7 @@
|
||||||
<file>./src</file>
|
<file>./src</file>
|
||||||
<file>./tests</file>
|
<file>./tests</file>
|
||||||
<exclude-pattern>*/Fixtures/*</exclude-pattern>
|
<exclude-pattern>*/Fixtures/*</exclude-pattern>
|
||||||
|
<exclude-pattern>*/LegacyClassnames.php</exclude-pattern>
|
||||||
|
|
||||||
<!-- Excludes for PHPCS Code Style -->
|
<!-- Excludes for PHPCS Code Style -->
|
||||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||||
|
|
|
@ -21,7 +21,11 @@
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory>./src/</directory>
|
<directory>./src</directory>
|
||||||
|
<exclude>
|
||||||
|
<directory>./src/Standards/Typo3Update/Sniffs/</directory>
|
||||||
|
<file>./src/Standards/Typo3Update/Configuration/LegacyClassnames.php</file>
|
||||||
|
</exclude>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -100,7 +100,7 @@ class LegacyClassnameFeature implements FeatureInterface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->legacyMapping->isLegacyClassname($classname);
|
return $this->legacyMapping->isCaseInsensitiveLegacyClassname($classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,6 +45,7 @@ final class LegacyClassnameMapping
|
||||||
|
|
||||||
return static::$instance;
|
return static::$instance;
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
private function __clone()
|
private function __clone()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -54,6 +55,7 @@ final class LegacyClassnameMapping
|
||||||
private function __wakeup()
|
private function __wakeup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
if (is_file(Options::getMappingFile())) {
|
if (is_file(Options::getMappingFile())) {
|
||||||
|
@ -109,12 +111,21 @@ final class LegacyClassnameMapping
|
||||||
* @param string $classname
|
* @param string $classname
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isLegacyClassname($classname, $insensitive = true)
|
public function isLegacyClassname($classname)
|
||||||
{
|
{
|
||||||
$lowerVersion = $classname;
|
return $this->isLegacyTypo3Classname($classname) || $this->isLegacyMappingClassname($classname);
|
||||||
if ($insensitive) {
|
}
|
||||||
$classname = strtolower($classname);
|
|
||||||
}
|
/**
|
||||||
|
* Checks whether a mapping exists for the given $classname,
|
||||||
|
* indicating it's legacy.
|
||||||
|
*
|
||||||
|
* @param string $classname
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isCaseInsensitiveLegacyClassname($classname)
|
||||||
|
{
|
||||||
|
$lowerVersion = strtolower($classname);
|
||||||
|
|
||||||
return $this->isLegacyTypo3Classname($classname) || $this->isLegacyMappingClassname($classname)
|
return $this->isLegacyTypo3Classname($classname) || $this->isLegacyMappingClassname($classname)
|
||||||
|| $this->isLegacyTypo3Classname($lowerVersion) || $this->isLegacyMappingClassname($lowerVersion);
|
|| $this->isLegacyTypo3Classname($lowerVersion) || $this->isLegacyMappingClassname($lowerVersion);
|
||||||
|
@ -130,7 +141,7 @@ final class LegacyClassnameMapping
|
||||||
return $this->typo3Mappings[$this->getTypo3MappingKey($classname)];
|
return $this->typo3Mappings[$this->getTypo3MappingKey($classname)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this>mappings[$this->getLegacyMappingKey($classname)];
|
return $this->mappings[$this->getLegacyMappingKey($classname)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,12 +150,7 @@ final class LegacyClassnameMapping
|
||||||
*/
|
*/
|
||||||
protected function getTypo3MappingKey($classname)
|
protected function getTypo3MappingKey($classname)
|
||||||
{
|
{
|
||||||
$lowerVersion = strtolower($classname);
|
return $this->typo3MappingsKeys[strtolower($classname)];
|
||||||
if (isset($this->typo3MappingsKeys[$lowerVersion])) {
|
|
||||||
return $this->typo3MappingsKeys[$lowerVersion];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $classname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,12 +159,7 @@ final class LegacyClassnameMapping
|
||||||
*/
|
*/
|
||||||
protected function getLegacyMappingKey($classname)
|
protected function getLegacyMappingKey($classname)
|
||||||
{
|
{
|
||||||
$lowerVersion = strtolower($classname);
|
return $this->mappingsKeys[strtolower($classname)];
|
||||||
if (isset($this->mappingsKeys[$lowerVersion])) {
|
|
||||||
return $this->mappingsKeys[$lowerVersion];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $classname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,7 +168,7 @@ final class LegacyClassnameMapping
|
||||||
*/
|
*/
|
||||||
protected function isLegacyTypo3Classname($classname)
|
protected function isLegacyTypo3Classname($classname)
|
||||||
{
|
{
|
||||||
return isset($this->typo3MappingsKeys[$classname]);
|
return isset($this->typo3Mappings[$classname]) || isset($this->typo3MappingsKeys[$classname]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,7 +177,7 @@ final class LegacyClassnameMapping
|
||||||
*/
|
*/
|
||||||
protected function isLegacyMappingClassname($classname)
|
protected function isLegacyMappingClassname($classname)
|
||||||
{
|
{
|
||||||
return isset($this->mappingsKeys[$classname]);
|
return isset($this->mappings[$classname]) || isset($this->mappingsKeys[$classname]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,6 +211,7 @@ final class LegacyClassnameMapping
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to persist new mappings.
|
* Used to persist new mappings.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,14 +64,14 @@ class LegacyClassnameMappingTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function insensitivityLookupWorks()
|
public function inCaseSensitivityLookupWorks()
|
||||||
{
|
{
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$this->subject->isLegacyClassname('Tx_About_Controller_Aboutcontroller', false),
|
$this->subject->isLegacyClassname('Tx_Extbase_Domain_Model_Backenduser'),
|
||||||
'Classname was returned to be legacy but should not due to lowercase version and case sensitivity.'
|
'Classname was returned to be legacy but should not due to lowercase version and case sensitivity.'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->subject->isLegacyClassname('Tx_About_Controller_Aboutcontroller'),
|
$this->subject->isCaseInsensitiveLegacyClassname('Tx_Extbase_Domain_Model_Backenduser'),
|
||||||
'Classname was not returned to be legacy but should due to case insensitivity.'
|
'Classname was not returned to be legacy but should due to case insensitivity.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,41 @@ class LegacyClassnameMappingTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
public function weCanRetrieveNewClassname()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'TYPO3\CMS\Extbase\Command\HelpCommandController',
|
||||||
|
$this->subject->getNewClassname('Tx_Extbase_Command_HelpCommandController'),
|
||||||
|
'New class name could not be fetched.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function nothingWillBePersistedUntilWeAddSomething()
|
||||||
|
{
|
||||||
|
$this->subject->persistMappings();
|
||||||
|
$this->assertSame(
|
||||||
|
file_get_contents($this->getFixturePath('MappingContent.php')),
|
||||||
|
file_get_contents(vfsStream::url('root/LegacyClassnames.php')),
|
||||||
|
'File content should not be changed.'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->subject->addLegacyClassname('Tx_ExtName_Controller_ExampleController', '\\Vendor\\ExtName\\Controller\\ExampleController');
|
||||||
|
$this->subject->persistMappings();
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
file_get_contents($this->getFixturePath('ExpectedMappingContent.php')),
|
||||||
|
file_get_contents(vfsStream::url('root/LegacyClassnames.php')),
|
||||||
|
'File content is not changed as expected.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @runInSeparateProcess Because of file operations.
|
||||||
|
*/
|
||||||
public function addingLegacyClassnamesWillAdjustLookupAndBePersisted()
|
public function addingLegacyClassnamesWillAdjustLookupAndBePersisted()
|
||||||
{
|
{
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
|
@ -92,13 +127,19 @@ class LegacyClassnameMappingTest extends TestCase
|
||||||
$this->subject->isLegacyClassname('Tx_ExtName_Controller_ExampleController'),
|
$this->subject->isLegacyClassname('Tx_ExtName_Controller_ExampleController'),
|
||||||
'Classname is configured but not returned to be legacy.'
|
'Classname is configured but not returned to be legacy.'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$this->subject->persistMappings();
|
/**
|
||||||
|
* @test
|
||||||
|
* @runInSeparateProcess Because of file operations.
|
||||||
|
*/
|
||||||
|
public function weCanRetrieveNewClassnameAddedBefore()
|
||||||
|
{
|
||||||
|
$this->subject->addLegacyClassname('Tx_ExtName_Controller_ExampleController', '\\Vendor\\ExtName\\Controller\\ExampleController');
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
file_get_contents($this->getFixturePath('ExpectedMappingContent.php')),
|
'\\Vendor\\ExtName\\Controller\\ExampleController',
|
||||||
file_get_contents(vfsStream::url('root/LegacyClassnames.php')),
|
$this->subject->getNewClassname('Tx_ExtName_Controller_ExampleController'),
|
||||||
'Persisted mappings are not as expected.'
|
'New class name could not be fetched.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue