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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function refactor(Node $node): MethodCall|StaticCall|null
return null;
}

$secondType = $this->getType($node->getArgs()[1]->value);
if ($secondType instanceof UnionType) {
return null;
}

$value = ($type->getConstantScalarValues()[0] ?? null);
if ($value === 0) {
$args = $node->getArgs();
Expand Down
28 changes: 28 additions & 0 deletions tests/Issues/EmptyUnion/EmptyUnionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Issues\EmptyUnion;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class EmptyUnionTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
19 changes: 19 additions & 0 deletions tests/Issues/EmptyUnion/Fixture/some_test.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\PHPUnit\Tests\Issues\EmptyUnion\Fixture;

use ArrayIterator;
use PHPUnit\Framework\TestCase;

final class SomeTest extends TestCase
{
public function testSomething()
{
$this->assertCount(0, $this->someCall());
}

public function someCall(): ?ArrayIterator
{
return new ArrayIterator([]);
}
}
14 changes: 14 additions & 0 deletions tests/Issues/EmptyUnion/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
AssertCountWithZeroToAssertEmptyRector::class,
AssertEmptyNullableObjectToAssertInstanceofRector::class,
]);
};
Loading