mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-31 12:42:05 +01:00
[PHPUnit] Add ClassMethod/RemoveEmptyTestMethodRector
This commit is contained in:
parent
8788c9b02d
commit
9944485d11
@ -30,3 +30,4 @@ services:
|
||||
Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector: null
|
||||
Rector\DeadCode\Rector\If_\SimplifyIfElseWithSameContentRector: null
|
||||
Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector: null
|
||||
Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector: null
|
||||
|
@ -1,4 +1,4 @@
|
||||
# All 430 Rectors Overview
|
||||
# All 432 Rectors Overview
|
||||
|
||||
- [Projects](#projects)
|
||||
- [General](#general)
|
||||
@ -4536,6 +4536,27 @@ Fix data provider annotation typos
|
||||
|
||||
<br>
|
||||
|
||||
### `GetMockBuilderGetMockToCreateMockRector`
|
||||
|
||||
- class: `Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector`
|
||||
|
||||
Remove getMockBuilder() to createMock()
|
||||
|
||||
```diff
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
- $applicationMock = $this->getMockBuilder('SomeClass')
|
||||
- ->disableOriginalConstructor()
|
||||
- ->getMock();
|
||||
+ $applicationMock = $this->createMock('SomeClass');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `GetMockRector`
|
||||
|
||||
- class: `Rector\PHPUnit\Rector\GetMockRector`
|
||||
@ -4582,6 +4603,28 @@ Data provider methods cannot start with "test" prefix
|
||||
|
||||
<br>
|
||||
|
||||
### `RemoveEmptyTestMethodRector`
|
||||
|
||||
- class: `Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector`
|
||||
|
||||
Remove empty test methods
|
||||
|
||||
```diff
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
- /**
|
||||
- * testGetTranslatedModelField method
|
||||
- *
|
||||
- * @return void
|
||||
- */
|
||||
- public function testGetTranslatedModelField()
|
||||
- {
|
||||
- }
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `RemoveExpectAnyFromMockRector`
|
||||
|
||||
- class: `Rector\PHPUnit\Rector\MethodCall\RemoveExpectAnyFromMockRector`
|
||||
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPUnit\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Rector\AbstractPHPUnitRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\RemoveEmptyTestMethodRector\RemoveEmptyTestMethodRectorTest
|
||||
*/
|
||||
final class RemoveEmptyTestMethodRector extends AbstractPHPUnitRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Remove empty test methods', [
|
||||
new CodeSample(
|
||||
<<<'PHP'
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* testGetTranslatedModelField method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTranslatedModelField()
|
||||
{
|
||||
}
|
||||
}
|
||||
PHP
|
||||
,
|
||||
<<<'PHP'
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
}
|
||||
PHP
|
||||
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'test*')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\RemoveEmptyTestMethodRector\Fixture;
|
||||
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* testGetTranslatedModelField method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTranslatedModelField()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\RemoveEmptyTestMethodRector\Fixture;
|
||||
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\RemoveEmptyTestMethodRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class RemoveEmptyTestMethodRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideDataForTest()
|
||||
*/
|
||||
public function test(string $file): void
|
||||
{
|
||||
$this->doTestFile($file);
|
||||
}
|
||||
|
||||
public function provideDataForTest(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return RemoveEmptyTestMethodRector::class;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user