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
@@ -0,0 +1,37 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Fixture;

use CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Source\SomeTypeObject;
use PHPUnit\Framework\TestCase;

final class KeepCustomMessage extends TestCase
{
public function test()
{
$someObject = mt_rand(0, 1) ? new SomeTypeObject() : null;

$this->assertNull($someObject, 'some message');
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Fixture;

use CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Source\SomeTypeObject;
use PHPUnit\Framework\TestCase;

final class KeepCustomMessage extends TestCase
{
public function test()
{
$someObject = mt_rand(0, 1) ? new SomeTypeObject() : null;

$this->assertNotInstanceOf(\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Source\SomeTypeObject::class, $someObject, 'some message');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function test()
}
}
CODE_SAMPLE

,
<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -99,7 +98,6 @@ public function refactor(Node $node): ?Node
}

$firstArgType = $this->getType($firstArg->value);

if (! $firstArgType instanceof UnionType) {
return null;
}
Expand All @@ -118,9 +116,15 @@ public function refactor(Node $node): ?Node

$fullyQualified = new FullyQualified($pureType->getClassName());

$customMessageArg = $node->getArgs()[1] ?? null;

$node->args[0] = new Arg(new ClassConstFetch($fullyQualified, 'class'));
$node->args[1] = $firstArg;

if ($customMessageArg instanceof Arg) {
$node->args[] = $customMessageArg;
}

return $node;
}
}