mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
[PHPUnit] Improve GetMockRector
This commit is contained in:
parent
760d0eff21
commit
e343b39633
@ -13,6 +13,9 @@ use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see https://github.com/sebastianbergmann/phpunit/blob/5.7.0/src/Framework/TestCase.php#L1623
|
||||
* @see https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L1452
|
||||
*
|
||||
* @see \Rector\PHPUnit\Tests\Rector\GetMockRector\GetMockRectorTest
|
||||
*/
|
||||
final class GetMockRector extends AbstractPHPUnitRector
|
||||
@ -45,8 +48,15 @@ final class GetMockRector extends AbstractPHPUnitRector
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count($node->args) !== 1) {
|
||||
return null;
|
||||
if ($node instanceof MethodCall) {
|
||||
if ($node->var instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// narrow args to one
|
||||
if (count($node->args) > 1) {
|
||||
$node->args = [$node->args[0]];
|
||||
}
|
||||
|
||||
$node->name = new Identifier('createMock');
|
||||
|
@ -7,9 +7,6 @@ final class MyGetMockTest extends \PHPUnit\Framework\TestCase
|
||||
public function test()
|
||||
{
|
||||
$firstMock = $this->getMock('SomeClass');
|
||||
|
||||
$secondMock = $this->buildMock()
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,9 +21,6 @@ final class MyGetMockTest extends \PHPUnit\Framework\TestCase
|
||||
public function test()
|
||||
{
|
||||
$firstMock = $this->createMock('SomeClass');
|
||||
|
||||
$secondMock = $this->buildMock()
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\GetMockRector\Fixture;
|
||||
|
||||
final class GetMockMultiTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$firstMock = $this->getMock('LDUser', [], [], '', false);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\GetMockRector\Fixture;
|
||||
|
||||
final class GetMockMultiTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$firstMock = $this->createMock('LDUser');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\GetMockRector\Fixture;
|
||||
|
||||
final class SkipBuildMockTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$secondMock = $this->buildMock()
|
||||
->getMock();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\GetMockRector\Fixture;
|
||||
|
||||
final class StaticCallTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$firstMock = self::getMock('SomeClass');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\GetMockRector\Fixture;
|
||||
|
||||
final class StaticCallTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$firstMock = self::createMock('SomeClass');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user