mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
add few definitions
This commit is contained in:
parent
0d6cf108f5
commit
a5ce094ff4
@ -11,20 +11,9 @@ use PhpParser\Node\Name;
|
|||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\NodeChanger\IdentifierRenamer;
|
use Rector\NodeChanger\IdentifierRenamer;
|
||||||
use Rector\Rector\AbstractPHPUnitRector;
|
use Rector\Rector\AbstractPHPUnitRector;
|
||||||
|
use Rector\RectorDefinition\CodeSample;
|
||||||
|
use Rector\RectorDefinition\RectorDefinition;
|
||||||
|
|
||||||
/**
|
|
||||||
* Before:
|
|
||||||
* - $this->assertSame(10, count($anything), 'message');
|
|
||||||
* - $this->assertSame($value, {function}($anything), 'message');
|
|
||||||
* - $this->assertNotSame($value, {function}($anything), 'message');
|
|
||||||
* - $this->assertEquals($value, {function}($anything), 'message');
|
|
||||||
* - $this->assertNotEquals($value, {function}($anything), 'message');
|
|
||||||
*
|
|
||||||
* After:
|
|
||||||
* - $this->assertCount(10, $anything, 'message');
|
|
||||||
* - $this->assert{function}($value, $anything, 'message');
|
|
||||||
* - $this->assertNot{function}($value, $anything, 'message');
|
|
||||||
*/
|
|
||||||
final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -58,6 +47,18 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
|||||||
$this->identifierRenamer = $identifierRenamer;
|
$this->identifierRenamer = $identifierRenamer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDefinition(): RectorDefinition
|
||||||
|
{
|
||||||
|
return new RectorDefinition('Turns vague php-only method in PHPUnit Test Case to more specific', [
|
||||||
|
new CodeSample('$this->assertSame(10, count($anything), "message");', '$this->assertCount(10, $anything, "message");'),
|
||||||
|
new CodeSample('$this->assertSame($value, {function}($anything), "message");', '$this->assert{function}($value, $anything, "message\");'),
|
||||||
|
new CodeSample('$this->assertEquals($value, {function}($anything), "message");', '$this->assert{function}($value, $anything, "message\");'),
|
||||||
|
|
||||||
|
new CodeSample('$this->assertNotSame($value, {function}($anything), "message");', '$this->assertNot{function}($value, $anything, "message")'),
|
||||||
|
new CodeSample('$this->assertNotEquals($value, {function}($anything), "message");', '$this->assertNot{function}($value, $anything, "message")'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function isCandidate(Node $node): bool
|
public function isCandidate(Node $node): bool
|
||||||
{
|
{
|
||||||
if (! $this->isInTestClass($node)) {
|
if (! $this->isInTestClass($node)) {
|
||||||
|
@ -9,16 +9,9 @@ use PhpParser\Node\Expr\MethodCall;
|
|||||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||||
use Rector\NodeChanger\IdentifierRenamer;
|
use Rector\NodeChanger\IdentifierRenamer;
|
||||||
use Rector\Rector\AbstractPHPUnitRector;
|
use Rector\Rector\AbstractPHPUnitRector;
|
||||||
|
use Rector\RectorDefinition\CodeSample;
|
||||||
|
use Rector\RectorDefinition\RectorDefinition;
|
||||||
|
|
||||||
/**
|
|
||||||
* - Before:
|
|
||||||
* - $this->assertTrue($foo === $bar, 'message');
|
|
||||||
* - $this->assertFalse($foo >= $bar, 'message');
|
|
||||||
*
|
|
||||||
* - After:
|
|
||||||
* - $this->assertSame($bar, $foo, 'message');
|
|
||||||
* - $this->assertLessThanOrEqual($bar, $foo, 'message');
|
|
||||||
*/
|
|
||||||
final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -57,6 +50,14 @@ final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
|||||||
$this->identifierRenamer = $identifierRenamer;
|
$this->identifierRenamer = $identifierRenamer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDefinition(): RectorDefinition
|
||||||
|
{
|
||||||
|
return new RectorDefinition('Turns === comparisons to their method name alternatives in PHPUnit Test Case', [
|
||||||
|
new CodeSample('$this->assertTrue($foo === $bar, "message");', '$this->assertSame($bar, $foo, "message");'),
|
||||||
|
new CodeSample('$this->assertFalse($foo >= $bar, "message");', '$this->assertLessThanOrEqual($bar, $foo, "message");'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function isCandidate(Node $node): bool
|
public function isCandidate(Node $node): bool
|
||||||
{
|
{
|
||||||
if (! $this->isInTestClass($node)) {
|
if (! $this->isInTestClass($node)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user