Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.3] PhpUnitDedicateAssertFixer - support PHP 7.3 #4211

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -10,6 +10,7 @@ PHP 7.3 test.
"mb_str_functions": 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 @@ -48,6 +49,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 @@ -94,6 +96,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