public function testResourceRepository() { $documentManager = $this->createDocumentManagerMock(); $documentManager->expects($this->once())->method('getClassMetadata')->with($this->identicalTo($documentName = 'document'))->will($this->returnValue($classMetadata = $this->createClassMetadataMock())); $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($documentName)); $this->resourceRegistry->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()]))); $resource->expects($this->once())->method('getModel')->will($this->returnValue($documentName)); $documentManager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->createUnitOfWorkMock())); $classMetadata->customRepositoryClassName = $repositoryClass = Repository::class; $this->assertInstanceOf($repositoryClass, $repository = $this->repositoryFactory->getRepository($documentManager, $documentName)); $this->assertSame($repository, $this->repositoryFactory->getRepository($documentManager, $documentName)); }
/** * {@inheritdoc} */ protected function createResourceRepository($class, DocumentManager $documentManager, ClassMetadata $metadata, ResourceInterface $resource = null) { if ($resource !== null && is_a($class, TranslatableRepository::class, true)) { return new $class($documentManager, $documentManager->getUnitOfWork(), $metadata, $resource, $this->getLocaleContext()); } return parent::createResourceRepository($class, $documentManager, $metadata, $resource); }