A coworker wants to mock the entity manager in a test. He has this code:
...
$em = $this->createMock(EntityManager::class);
$myRepository = new NewslettersStatisticSnapshotRepository(
$em,
NewslettersStatisticSnapshot::class
);
$em->method('getRepository')->willReturn($myRepository);
...
... and when I run his test, I get this:
TypeError: Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, string given
How can I dig up metadata for this class?
getRepositoryand use those repositories returned, then this approach is absolutely reasonable. - JakumiNewslettersStatisticSnapshotRepository::__constructcalls its parent class' constructor (EntityRepository::__construct) - or the constructor isn't even implemented in the "custom" repository. anyway, the second parameter really is a string, and the second parameter should be ClassMetadata. so that's the error message happening right there and nowhere else. - Jakumi