Skip to content

Commit 4d504c4

Browse files
committed
minor #4211 [7.3] PhpUnitDedicateAssertFixer - support PHP 7.3 (kubawerlos)
This PR was merged into the 2.12 branch. Discussion ---------- [7.3] PhpUnitDedicateAssertFixer - support PHP 7.3 Commits ------- 7c567e8 [7.3] PhpUnitDedicateAssertFixer - support PHP 7.3
2 parents bbbaa57 + 7c567e8 commit 4d504c4

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ private function fixAssertTrueFalse(Tokens $tokens, array $assertCall)
305305
$tokens[$testOpenIndex] = new Token(',');
306306

307307
$tokens->clearTokenAndMergeSurroundingWhitespace($testCloseIndex);
308+
$commaIndex = $tokens->getPrevMeaningfulToken($testCloseIndex);
309+
if ($tokens[$commaIndex]->equals(',')) {
310+
$tokens->removeTrailingWhitespace($commaIndex);
311+
$tokens->clearAt($commaIndex);
312+
}
308313

309314
if (!$tokens[$testOpenIndex + 1]->isWhitespace()) {
310315
$tokens->insertAt($testOpenIndex + 1, new Token([T_WHITESPACE, ' ']));
@@ -426,6 +431,12 @@ private function removeFunctionCall(Tokens $tokens, $callNSIndex, $callIndex, $o
426431
}
427432

428433
$tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
434+
$commaIndex = $tokens->getPrevMeaningfulToken($closeIndex);
435+
if ($tokens[$commaIndex]->equals(',')) {
436+
$tokens->removeTrailingWhitespace($commaIndex);
437+
$tokens->clearAt($commaIndex);
438+
}
439+
429440
$tokens->clearTokenAndMergeSurroundingWhitespace($closeIndex);
430441
}
431442
}

tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,58 @@ public function provideTestAssertCountCases()
476476
],
477477
];
478478
}
479+
480+
/**
481+
* @param string $expected
482+
* @param string $input
483+
*
484+
* @requires PHP 7.3
485+
* @dataProvider provideFix73Cases
486+
*/
487+
public function testFix73($expected, $input)
488+
{
489+
$this->doTest($expected, $input);
490+
}
491+
492+
public function provideFix73Cases()
493+
{
494+
return [
495+
[
496+
'<?php $this->assertNan($a, );',
497+
'<?php $this->assertTrue(is_nan($a), );',
498+
],
499+
[
500+
'<?php $this->assertNan($a);',
501+
'<?php $this->assertTrue(is_nan($a, ));',
502+
],
503+
[
504+
'<?php $this->assertNan($a, );',
505+
'<?php $this->assertTrue(is_nan($a, ), );',
506+
],
507+
[
508+
'<?php $this->assertInternalType(\'array\', $a,);',
509+
'<?php $this->assertTrue(is_array($a,),);',
510+
],
511+
[
512+
'<?php
513+
$this->assertNan($b);
514+
',
515+
'<?php
516+
$this->assertTrue(\is_nan($b,));
517+
',
518+
],
519+
[
520+
'<?php
521+
$this->assertFileExists($f, \'message\',);
522+
',
523+
'<?php
524+
$this->assertTrue(file_exists($f,), \'message\',);
525+
',
526+
],
527+
[
528+
'<?php $this->assertNan($y , );',
529+
'<?php $this->assertTrue(is_nan($y) , );',
530+
],
531+
];
532+
}
479533
}

tests/Fixtures/Integration/misc/PHP7_3.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP 7.3 test.
1111
"method_chaining_indentation": true,
1212
"multiline_whitespace_before_semicolons": true,
1313
"native_function_invocation": {"include": ["get_class"]},
14+
"php_unit_dedicate_assert": true,
1415
"php_unit_test_case_static_method_calls": {"call_type": "this"},
1516
"strict_param": true
1617
}
@@ -51,6 +52,7 @@ $c = \get_class($d, ); // `native_function_invocation` rule
5152
$a = rtrim($b, ); // `no_alias_functions` rule
5253
$foo->bar($arg1, $arg2, ); // `no_spaces_inside_parenthesis` rule
5354
$this->assertTrue($a, ); // `php_unit_construct` rule
55+
$this->assertNan($a, ); // `php_unit_dedicate_assert` rule
5456
final class MyTest extends \PHPUnit_Framework_TestCase
5557
{
5658
public function testFoo(): void
@@ -99,6 +101,7 @@ $c = get_class($d, ); // `native_function_invocation` rule
99101
$a = chop($b, ); // `no_alias_functions` rule
100102
$foo->bar( $arg1, $arg2, );// `no_spaces_inside_parenthesis` rule
101103
$this->assertSame(true, $a, ); // `php_unit_construct` rule
104+
$this->assertTrue(is_nan($a, ), ); // `php_unit_dedicate_assert` rule
102105
final class MyTest extends \PHPUnit_Framework_TestCase
103106
{
104107
public function testFoo(): void

0 commit comments

Comments
 (0)