/** * Deletes an entity from the repo * * @param object $entity The entity to delete * * @return void * * @throws OrmException if the entity could not be deleted */ public function remove($entity) { $idAccessorRegistry = $this->unitOfWork->getEntityRegistry()->getIdAccessorRegistry(); $entityId = $idAccessorRegistry->getEntityId($entity); $this->updateMap(); if (!in_array($entityId, $this->map)) { throw new EntityNotFoundException(); } $colJoinName = $this->relation->colJoinName(); $mapObject = $this->mapRepository->findOne()->with($colJoinName, Operator::EQUAL, $entityId)->getItem(); $this->mapRepository->remove($mapObject); $this->map = array_diff($this->map, [$entityId]); }
/** * @expectedException \Joomla\ORM\Exception\OrmException */ public function testDeleteEmptyId() { $article = new Article(); $article->title = "Non-existant Article"; $article->teaser = "This article is not existant and has no id"; $article->body = "It serves test purposes only and should never go into the database."; $article->author = __METHOD__; $article->license = 'CC'; /** @noinspection PhpUndefinedFieldInspection */ $article->parent_id = 0; $this->repo->remove($article); $this->repo->commit(); }
/** * @testdox remove() schedules the object for deletion on the unit of work */ public function testRemove() { $this->unitOfWork->expects($this->once())->method('scheduleForDeletion'); $this->repo->remove(new Article()); }