Skip to content

Commit

Permalink
Avoid prophecy
Browse files Browse the repository at this point in the history
It is no longer bundled by default in PHPUnit, which causes a build
failure. Rather than requiring the missing package, migrating to PHPUnit
mocks should result in code easier to analyse by SA tools.

Fixes doctrine#401
  • Loading branch information
greg0ire committed Aug 28, 2022
1 parent 3322f51 commit 42ea3c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"doctrine/dbal": "^2.13 || ^3.0",
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
"doctrine/orm": "^2.7.0",
"jangregor/phpstan-prophecy": "^1",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5 || ^9.5",
"symfony/cache": "^5.0 || ^6.0",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ parameters:

includes:
- phpstan-baseline.neon
- vendor/jangregor/phpstan-prophecy/extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Common\DataFixtures\TestEntity\Role;
use OutOfBoundsException;
use Prophecy\Prophecy\ProphecyInterface;
use stdClass;

use function assert;

class ReferenceRepositoryTest extends BaseTest
{
public function testReferenceEntry(): void
Expand Down Expand Up @@ -189,19 +186,27 @@ public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork(): void
$role = new Role();
$identitiesExpected = ['id' => 1];

$uow = $this->prophesize(UnitOfWork::class);
assert($uow instanceof UnitOfWork || $uow instanceof ProphecyInterface);
$uow->isInIdentityMap($role)->shouldBeCalledTimes(2)->willReturn(true, false);

$classMetadata = $this->prophesize(ClassMetadata::class);
$classMetadata->getIdentifierValues($role)->shouldBeCalled()->willReturn($identitiesExpected);
$uow = $this->createMock(UnitOfWork::class);
$uow->expects($this->exactly(2))
->method('isInIdentityMap')
->with($role)
->willReturn(true, false);

$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->expects($this->once())
->method('getIdentifierValues')
->with($role)
->willReturn($identitiesExpected);

$em = $this->createMock(EntityManagerInterface::class);
$em->method('getUnitOfWork')
->willReturn($uow);
$em->expects($this->once())
->method('getClassMetadata')
->with(Role::class)
->willReturn($classMetadata);

$em = $this->prophesize(EntityManagerInterface::class);
assert($em instanceof EntityManagerInterface || $em instanceof ProphecyInterface);
$em->getUnitOfWork()->shouldBeCalled()->willReturn($uow);
$em->getClassMetadata(Role::class)->shouldBeCalled()->willReturn($classMetadata);

$referenceRepository = new ReferenceRepository($em->reveal());
$referenceRepository = new ReferenceRepository($em);
$referenceRepository->setReference('entity', $role);
$identities = $referenceRepository->getIdentities();

Expand Down

0 comments on commit 42ea3c8

Please sign in to comment.