Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/set/dead-code/dead-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 44 additions & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 430 Rectors Overview
# All 432 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
{
}

?>
Original file line number Diff line number Diff line change
@@ -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;
}
}