Skip to content

Commit e65ac7d

Browse files
committed
Merge branch '2.12' into 2.14
2 parents f83f648 + 2e2bc2e commit e65ac7d

File tree

8 files changed

+85
-6
lines changed

8 files changed

+85
-6
lines changed

.composer-require-checker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"symbol-whitelist" : [
3+
"Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
34
"PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
45
"PHPUnit\\Framework\\Constraint\\IsIdentical",
56
"PHPUnit\\Framework\\TestCase",

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
<<: *STANDARD_TEST_JOB
8484
stage: Test
8585
php: 7.1
86-
env: SYMFONY_DEPRECATIONS_HELPER=weak PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="~4.1.0"
86+
env: SYMFONY_DEPRECATIONS_HELPER=disabled PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="~4.1.0"
8787

8888
-
8989
<<: *STANDARD_TEST_JOB

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
4343
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1",
4444
"phpunitgoodpractices/traits": "^1.8",
45-
"symfony/phpunit-bridge": "^4.0"
45+
"symfony/phpunit-bridge": "^4.3"
4646
},
4747
"suggest": {
4848
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",

src/Fixer/Casing/LowercaseStaticReferenceFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function baz(?self $x) : SELF
6262
}
6363
}
6464
',
65-
new VersionSpecification(71000)
65+
new VersionSpecification(70100)
6666
),
6767
]
6868
);

src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)) {

src/Runner/FileFilterIterator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ private function dispatchEvent($name, Event $event)
105105
return;
106106
}
107107

108-
$this->eventDispatcher->dispatch($name, $event);
108+
// BC compatibility < Sf 4.3
109+
if (
110+
!$this->eventDispatcher instanceof \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
111+
) {
112+
$this->eventDispatcher->dispatch($name, $event);
113+
114+
return;
115+
}
116+
117+
$this->eventDispatcher->dispatch($event, $name);
109118
}
110119
}

src/Runner/Runner.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ private function dispatchEvent($name, Event $event)
294294
return;
295295
}
296296

297-
$this->eventDispatcher->dispatch($name, $event);
297+
// BC compatibility < Sf 4.3
298+
if (
299+
!$this->eventDispatcher instanceof \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
300+
) {
301+
$this->eventDispatcher->dispatch($name, $event);
302+
303+
return;
304+
}
305+
306+
$this->eventDispatcher->dispatch($event, $name);
298307
}
299308
}

tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function testFix($expected, $input = null, array $config = [])
4040
public function provideTestFixCases()
4141
{
4242
return [
43+
'class_mapping' => [
44+
'<?php new PHPUnit\Framework\Error\Error();',
45+
'<?php new PHPUnit_Framework_Error();',
46+
],
47+
'class_mapping_bogus_fqcn' => [
48+
'<?php new \PHPUnit\Framework\MockObject\Stub\ReturnStub();',
49+
'<?php new \PHPUnit_Framework_MockObject_Stub_Return();',
50+
],
4351
[
4452
'<?php
4553
final class MyTest extends \PHPUnit\Framework\TestCase

0 commit comments

Comments
 (0)