Skip to content

Commit

Permalink
minor #4211 [7.3] PhpUnitDedicateAssertFixer - support PHP 7.3 (kubaw…
Browse files Browse the repository at this point in the history
…erlos)

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
  • Loading branch information
keradus committed Jan 4, 2019
2 parents bbbaa57 + 7c567e8 commit 4d504c4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ private function fixAssertTrueFalse(Tokens $tokens, array $assertCall)
$tokens[$testOpenIndex] = new Token(',');

$tokens->clearTokenAndMergeSurroundingWhitespace($testCloseIndex);
$commaIndex = $tokens->getPrevMeaningfulToken($testCloseIndex);
if ($tokens[$commaIndex]->equals(',')) {
$tokens->removeTrailingWhitespace($commaIndex);
$tokens->clearAt($commaIndex);
}

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

$tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
$commaIndex = $tokens->getPrevMeaningfulToken($closeIndex);
if ($tokens[$commaIndex]->equals(',')) {
$tokens->removeTrailingWhitespace($commaIndex);
$tokens->clearAt($commaIndex);
}

$tokens->clearTokenAndMergeSurroundingWhitespace($closeIndex);
}
}
54 changes: 54 additions & 0 deletions tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,58 @@ public function provideTestAssertCountCases()
],
];
}

/**
* @param string $expected
* @param string $input
*
* @requires PHP 7.3
* @dataProvider provideFix73Cases
*/
public function testFix73($expected, $input)
{
$this->doTest($expected, $input);
}

public function provideFix73Cases()
{
return [
[
'<?php $this->assertNan($a, );',
'<?php $this->assertTrue(is_nan($a), );',
],
[
'<?php $this->assertNan($a);',
'<?php $this->assertTrue(is_nan($a, ));',
],
[
'<?php $this->assertNan($a, );',
'<?php $this->assertTrue(is_nan($a, ), );',
],
[
'<?php $this->assertInternalType(\'array\', $a,);',
'<?php $this->assertTrue(is_array($a,),);',
],
[
'<?php
$this->assertNan($b);
',
'<?php
$this->assertTrue(\is_nan($b,));
',
],
[
'<?php
$this->assertFileExists($f, \'message\',);
',
'<?php
$this->assertTrue(file_exists($f,), \'message\',);
',
],
[
'<?php $this->assertNan($y , );',
'<?php $this->assertTrue(is_nan($y) , );',
],
];
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/Integration/misc/PHP7_3.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PHP 7.3 test.
"method_chaining_indentation": true,
"multiline_whitespace_before_semicolons": true,
"native_function_invocation": {"include": ["get_class"]},
"php_unit_dedicate_assert": true,
"php_unit_test_case_static_method_calls": {"call_type": "this"},
"strict_param": true
}
Expand Down Expand Up @@ -51,6 +52,7 @@ $c = \get_class($d, ); // `native_function_invocation` rule
$a = rtrim($b, ); // `no_alias_functions` rule
$foo->bar($arg1, $arg2, ); // `no_spaces_inside_parenthesis` rule
$this->assertTrue($a, ); // `php_unit_construct` rule
$this->assertNan($a, ); // `php_unit_dedicate_assert` rule
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testFoo(): void
Expand Down Expand Up @@ -99,6 +101,7 @@ $c = get_class($d, ); // `native_function_invocation` rule
$a = chop($b, ); // `no_alias_functions` rule
$foo->bar( $arg1, $arg2, );// `no_spaces_inside_parenthesis` rule
$this->assertSame(true, $a, ); // `php_unit_construct` rule
$this->assertTrue(is_nan($a, ), ); // `php_unit_dedicate_assert` rule
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testFoo(): void
Expand Down

0 comments on commit 4d504c4

Please sign in to comment.