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:
Daniel Siepmann 2017-05-04 12:46:39 +02:00
parent 666bbdb26a
commit b69c262288
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
5 changed files with 78 additions and 30 deletions

View file

@ -5,6 +5,7 @@
<file>./src</file>
<file>./tests</file>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/LegacyClassnames.php</exclude-pattern>
<!-- Excludes for PHPCS Code Style -->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">

View file

@ -21,7 +21,11 @@
<filter>
<whitelist>
<directory>./src/</directory>
<directory>./src</directory>
<exclude>
<directory>./src/Standards/Typo3Update/Sniffs/</directory>
<file>./src/Standards/Typo3Update/Configuration/LegacyClassnames.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>

View file

@ -100,7 +100,7 @@ class LegacyClassnameFeature implements FeatureInterface
return false;
}
return $this->legacyMapping->isLegacyClassname($classname);
return $this->legacyMapping->isCaseInsensitiveLegacyClassname($classname);
}
/**

View file

@ -45,6 +45,7 @@ final class LegacyClassnameMapping
return static::$instance;
}
// @codeCoverageIgnoreStart
private function __clone()
{
}
@ -54,6 +55,7 @@ final class LegacyClassnameMapping
private function __wakeup()
{
}
// @codeCoverageIgnoreEnd
private function __construct()
{
if (is_file(Options::getMappingFile())) {
@ -109,12 +111,21 @@ final class LegacyClassnameMapping
* @param string $classname
* @return bool
*/
public function isLegacyClassname($classname, $insensitive = true)
public function isLegacyClassname($classname)
{
$lowerVersion = $classname;
if ($insensitive) {
$classname = strtolower($classname);
}
return $this->isLegacyTypo3Classname($classname) || $this->isLegacyMappingClassname($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)
|| $this->isLegacyTypo3Classname($lowerVersion) || $this->isLegacyMappingClassname($lowerVersion);
@ -130,7 +141,7 @@ final class LegacyClassnameMapping
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)
{
$lowerVersion = strtolower($classname);
if (isset($this->typo3MappingsKeys[$lowerVersion])) {
return $this->typo3MappingsKeys[$lowerVersion];
}
return $classname;
return $this->typo3MappingsKeys[strtolower($classname)];
}
/**
@ -153,12 +159,7 @@ final class LegacyClassnameMapping
*/
protected function getLegacyMappingKey($classname)
{
$lowerVersion = strtolower($classname);
if (isset($this->mappingsKeys[$lowerVersion])) {
return $this->mappingsKeys[$lowerVersion];
}
return $classname;
return $this->mappingsKeys[strtolower($classname)];
}
/**
@ -167,7 +168,7 @@ final class LegacyClassnameMapping
*/
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)
{
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.
* @codeCoverageIgnore
*/
public function __destruct()
{

View file

@ -64,14 +64,14 @@ class LegacyClassnameMappingTest extends TestCase
/**
* @test
*/
public function insensitivityLookupWorks()
public function inCaseSensitivityLookupWorks()
{
$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.'
);
$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.'
);
}
@ -79,6 +79,41 @@ class LegacyClassnameMappingTest extends TestCase
/**
* @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()
{
$this->assertFalse(
@ -92,13 +127,19 @@ class LegacyClassnameMappingTest extends TestCase
$this->subject->isLegacyClassname('Tx_ExtName_Controller_ExampleController'),
'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(
file_get_contents($this->getFixturePath('ExpectedMappingContent.php')),
file_get_contents(vfsStream::url('root/LegacyClassnames.php')),
'Persisted mappings are not as expected.'
'\\Vendor\\ExtName\\Controller\\ExampleController',
$this->subject->getNewClassname('Tx_ExtName_Controller_ExampleController'),
'New class name could not be fetched.'
);
}