public function delete(File $file) { $this->pdo->beginTransaction(); try { if (!$this->fileSystem->delete($file->getUuid()->toString())) { throw new \RuntimeException('Failed to delete file'); } $this->objectRepository->delete(File::TYPE, $file->getUuid()); $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_give_an_entities_id() { $this->getId($this->file)->shouldReturn($this->file->getUuid()->toString()); }
public function it_can_will_error_and_roll_back_when_delete_fails(File $file) { $uuid = Uuid::uuid4(); $file->getUuid()->willReturn($uuid); $this->pdo->beginTransaction()->shouldBeCalled(); $this->fileSystem->delete($uuid->toString())->willReturn(false); $this->objectRepository->delete(File::TYPE, $uuid)->shouldNotBeCalled(); $this->pdo->rollBack()->shouldBeCalled(); $this->shouldThrow(\RuntimeException::class)->duringDelete($file); }