Fix prophecy mocking arg

This commit is contained in:
TomasVotruba 2020-02-25 20:59:19 +01:00
parent 3f7bc95129
commit 147b51b4c9
2 changed files with 25 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
@ -22,7 +23,7 @@ use Rector\Doctrine\Contract\Mapper\DoctrineEntityAndRepositoryMapperInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @see \Rector\Core\Tests\Rector\Architecture\DoctrineRepositoryAsService\DoctrineRepositoryAsServiceTest
* @see \Rector\Architecture\Tests\Rector\DoctrineRepositoryAsService\DoctrineRepositoryAsServiceTest
*/
final class ServiceLocatorToDIRector extends AbstractRector
{
@ -103,6 +104,12 @@ PHP
return null;
}
$firstArgumentValue = $node->args[0]->value;
// possible mocking → skip
if ($firstArgumentValue instanceof StaticCall) {
return null;
}
/** @var string|null $className */
$className = $node->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) {

View File

@ -0,0 +1,17 @@
<?php
namespace Rector\Architecture\Tests\Rector\DoctrineRepositoryAsService\Fixture;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
final class ItemRepositoryTest extends TestCase
{
public function testGetThrowsExceptionIfNotFound(): void
{
$entityManagerMock = $this->prophesize(EntityManagerInterface::class);
$entityManagerMock->getRepository(Argument::any());
}
}