diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index c742021..c1cb878 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -5,6 +5,7 @@
./src
./tests
*/Fixtures/*
+ */LegacyClassnames.php
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index a507cf9..f186f18 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -21,7 +21,11 @@
- ./src/
+ ./src
+
+ ./src/Standards/Typo3Update/Sniffs/
+ ./src/Standards/Typo3Update/Configuration/LegacyClassnames.php
+
diff --git a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php
index 0a25222..4b2d50c 100644
--- a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php
+++ b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php
@@ -100,7 +100,7 @@ class LegacyClassnameFeature implements FeatureInterface
return false;
}
- return $this->legacyMapping->isLegacyClassname($classname);
+ return $this->legacyMapping->isCaseInsensitiveLegacyClassname($classname);
}
/**
diff --git a/src/Standards/Typo3Update/Feature/LegacyClassnameMapping.php b/src/Standards/Typo3Update/Feature/LegacyClassnameMapping.php
index a60c92b..47201c5 100644
--- a/src/Standards/Typo3Update/Feature/LegacyClassnameMapping.php
+++ b/src/Standards/Typo3Update/Feature/LegacyClassnameMapping.php
@@ -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()
{
diff --git a/tests/Feature/LegacyClassnameMappingTest.php b/tests/Feature/LegacyClassnameMappingTest.php
index f420e7f..ea47cd4 100644
--- a/tests/Feature/LegacyClassnameMappingTest.php
+++ b/tests/Feature/LegacyClassnameMappingTest.php
@@ -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.'
);
}