/** * Constructor * * @param RepositoryInterface $entityRepository The entity repository * @param RepositoryInterface $mapRepository The mapping repository * @param HasManyThrough $relation The relation * @param UnitOfWorkInterface $unitOfWork The unit of work */ public function __construct(RepoInterface $entityRepository, RepoInterface $mapRepository, HasManyThrough $relation, UnitOfWorkInterface $unitOfWork) { $this->entityRepository = $entityRepository; $this->mapRepository = $mapRepository; $this->relation = $relation; $this->className = $entityRepository->getEntityClass(); $this->unitOfWork = $unitOfWork; }
public function testParentRelation() { $article = $this->repo->getById(2); $this->assertInstanceOf(RepositoryInterface::class, $article->children); $children = $article->children->getAll(); $this->assertEquals(2, count($children)); }
/** * @testdox The UnitOfWork detects an update made outside of it */ public function testChangesAreDetected() { $this->prepareDatabase(); $this->repo->add($this->entity1); $this->assertContains($this->entity1, $this->unitOfWork->getScheduledEntityInsertions(), "Entity should have been scheduled for insertion"); $this->assertNotContains($this->entity1, $this->unitOfWork->getScheduledEntityUpdates(), "Entity should not have been scheduled for update"); $this->entity1->setUsername("blah"); $this->unitOfWork->checkForUpdates(); /* * This is not a change, since the entity has not yet been inserted! */ $this->assertContains($this->entity1, $this->unitOfWork->getScheduledEntityInsertions(), "Entity should still be scheduled for insertion"); $this->assertNotContains($this->entity1, $this->unitOfWork->getScheduledEntityUpdates(), "Entity should still not be scheduled for update"); $this->unitOfWork->commit(); $this->entity1->setUsername("blub"); $this->unitOfWork->checkForUpdates(); $this->assertNotContains($this->entity1, $this->unitOfWork->getScheduledEntityInsertions(), "Entity should not longer be scheduled for insertion"); $this->assertContains($this->entity1, $this->unitOfWork->getScheduledEntityUpdates(), "Entity should now be scheduled for update"); }
/** * Create a new entity * * @param array $row A hash with the properties for the new entity * * @return object */ public function createFromArray(array $row) { return $this->entityRepository->createFromArray($row); }
/** * @testdox commit() is a proxy for commit() on the unit of work */ public function testCommit() { $this->unitOfWork->expects($this->once())->method('commit'); $this->repo->commit(); }