@@ -32,6 +32,18 @@ final class PhpUnitNamespacedFixer extends AbstractFixer implements Configuratio
3232 */
3333 private $ originalClassRegEx ;
3434
35+ /**
36+ * Class Mappings.
37+ *
38+ * * [original classname => new classname] Some classes which match the
39+ * original class regular expression do not have a same-compound name-
40+ * space class and need a dedicated translation table. This trans-
41+ * lation table is defined in @see configure.
42+ *
43+ * @var array|string[] Class Mappings
44+ */
45+ private $ classMap ;
46+
3547 /**
3648 * {@inheritdoc}
3749 */
@@ -81,10 +93,42 @@ public function configure(array $configuration = null)
8193
8294 if (PhpUnitTargetVersion::fulfills ($ this ->configuration ['target ' ], PhpUnitTargetVersion::VERSION_6_0 )) {
8395 $ this ->originalClassRegEx = '/^PHPUnit_\w+$/i ' ;
96+ // @noinspection ClassConstantCanBeUsedInspection
97+ $ this ->classMap = [
98+ 'PHPUnit_Extensions_PhptTestCase ' => 'PHPUnit\Runner\PhptTestCase ' ,
99+ 'PHPUnit_Framework_Constraint ' => 'PHPUnit\Framework\Constraint\Constraint ' ,
100+ 'PHPUnit_Framework_Constraint_StringMatches ' => 'PHPUnit\Framework\Constraint\StringMatchesFormatDescription ' ,
101+ 'PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider ' => 'PHPUnit\Framework\Constraint\JsonMatchesErrorMessageProvider ' ,
102+ 'PHPUnit_Framework_Constraint_PCREMatch ' => 'PHPUnit\Framework\Constraint\RegularExpression ' ,
103+ 'PHPUnit_Framework_Constraint_ExceptionMessageRegExp ' => 'PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression ' ,
104+ 'PHPUnit_Framework_Constraint_And ' => 'PHPUnit\Framework\Constraint\LogicalAnd ' ,
105+ 'PHPUnit_Framework_Constraint_Or ' => 'PHPUnit\Framework\Constraint\LogicalOr ' ,
106+ 'PHPUnit_Framework_Constraint_Not ' => 'PHPUnit\Framework\Constraint\LogicalNot ' ,
107+ 'PHPUnit_Framework_Constraint_Xor ' => 'PHPUnit\Framework\Constraint\LogicalXor ' ,
108+ 'PHPUnit_Framework_Error ' => 'PHPUnit\Framework\Error\Error ' ,
109+ 'PHPUnit_Framework_TestSuite_DataProvider ' => 'PHPUnit\Framework\DataProviderTestSuite ' ,
110+ 'PHPUnit_Framework_MockObject_Invocation_Static ' => 'PHPUnit\Framework\MockObject\Invocation\StaticInvocation ' ,
111+ 'PHPUnit_Framework_MockObject_Invocation_Object ' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation ' ,
112+ 'PHPUnit_Framework_MockObject_Stub_Return ' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub ' ,
113+ 'PHPUnit_Runner_Filter_Group_Exclude ' => 'PHPUnit\Runner\Filter\ExcludeGroupFilterIterator ' ,
114+ 'PHPUnit_Runner_Filter_Group_Include ' => 'PHPUnit\Runner\Filter\IncludeGroupFilterIterator ' ,
115+ 'PHPUnit_Runner_Filter_Test ' => 'PHPUnit\Runner\Filter\NameFilterIterator ' ,
116+ 'PHPUnit_Util_PHP ' => 'PHPUnit\Util\PHP\AbstractPhpProcess ' ,
117+ 'PHPUnit_Util_PHP_Default ' => 'PHPUnit\Util\PHP\DefaultPhpProcess ' ,
118+ 'PHPUnit_Util_PHP_Windows ' => 'PHPUnit\Util\PHP\WindowsPhpProcess ' ,
119+ 'PHPUnit_Util_Regex ' => 'PHPUnit\Util\RegularExpression ' ,
120+ 'PHPUnit_Util_TestDox_ResultPrinter_XML ' => 'PHPUnit\Util\TestDox\XmlResultPrinter ' ,
121+ 'PHPUnit_Util_TestDox_ResultPrinter_HTML ' => 'PHPUnit\Util\TestDox\HtmlResultPrinter ' ,
122+ 'PHPUnit_Util_TestDox_ResultPrinter_Text ' => 'PHPUnit\Util\TestDox\TextResultPrinter ' ,
123+ 'PHPUnit_Util_TestSuiteIterator ' => 'PHPUnit\Framework\TestSuiteIterator ' ,
124+ 'PHPUnit_Util_XML ' => 'PHPUnit\Util\Xml ' ,
125+ ];
84126 } elseif (PhpUnitTargetVersion::fulfills ($ this ->configuration ['target ' ], PhpUnitTargetVersion::VERSION_5_7 )) {
85127 $ this ->originalClassRegEx = '/^PHPUnit_Framework_TestCase|PHPUnit_Framework_Assert|PHPUnit_Framework_BaseTestListener|PHPUnit_Framework_TestListener$/i ' ;
128+ $ this ->classMap = [];
86129 } else {
87130 $ this ->originalClassRegEx = '/^PHPUnit_Framework_TestCase$/i ' ;
131+ $ this ->classMap = [];
88132 }
89133 }
90134
@@ -153,7 +197,15 @@ protected function createConfigurationDefinition()
153197 */
154198 private function generateReplacement ($ originalClassName )
155199 {
156- $ parts = explode ('_ ' , $ originalClassName );
200+ $ delimiter = '_ ' ;
201+ $ string = $ originalClassName ;
202+
203+ if (isset ($ this ->classMap [$ originalClassName ])) {
204+ $ delimiter = '\\' ;
205+ $ string = $ this ->classMap [$ originalClassName ];
206+ }
207+
208+ $ parts = explode ($ delimiter , $ string );
157209
158210 $ tokensArray = [];
159211 while (!empty ($ parts )) {
0 commit comments