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,44 @@
<?php

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

use PHPUnit\Framework\TestCase;

final class ArrowWithClassVariable extends TestCase
{
public function test($type)
{
$this->createMock('SomeType')
->method('someMethod')
->with($this->callback(
fn ($item): bool => $item instanceof $type &&
$item->getName() === 'name'
));
}
}

?>
-----
<?php

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

use PHPUnit\Framework\TestCase;

final class ArrowWithClassVariable extends TestCase
{
public function test($type)
{
$this->createMock('SomeType')
->method('someMethod')
->with($this->callback(
function ($item) use ($type): bool {
$this->assertInstanceOf($type, $item);
$this->assertSame('name', $item->getName());
return true;
}
));
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ public function create(array $exprs): ?array
}

if ($expr instanceof Instanceof_) {
if (! $expr->class instanceof Name) {
return null;
if ($expr->class instanceof Name) {
$classNameExpr = new ClassConstFetch(new FullyQualified($expr->class->name), 'class');
} else {
$classNameExpr = $expr->class;
}

$className = $expr->class->name;
$assertMethodCalls[] = $this->nodeFactory->createMethodCall(
'this',
'assertInstanceOf',
[new ClassConstFetch(new FullyQualified($className), 'class'), $expr->expr]
[$classNameExpr, $expr->expr]
);

continue;
Expand Down