Skip to content

Commit 01b4404

Browse files
committed
[PHPUnit] Handle mix AssertCountWithZeroToAssertEmptyRector + AssertEmptyNullableObjectToAssertInstanceofRector cause invalid assertNotInstanceof()
1 parent 6b34ad2 commit 01b4404

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\Issues\EmptyUnion;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class EmptyUnionTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\Issues\EmptyUnion\Fixture;
4+
5+
use ArrayIterator;
6+
use PHPUnit\Framework\TestCase;
7+
8+
final class SomeTest extends TestCase
9+
{
10+
public function testSomething()
11+
{
12+
$this->assertCount(0, $this->someCall());
13+
}
14+
15+
public function someCall(): ?ArrayIterator
16+
{
17+
return new ArrayIterator([]);
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
7+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->rules([
11+
AssertCountWithZeroToAssertEmptyRector::class,
12+
AssertEmptyNullableObjectToAssertInstanceofRector::class,
13+
]);
14+
};

0 commit comments

Comments
 (0)