setRepository = new FakeSetRepository(); $this->elementRepository = new FakeElementRepository(); $this->filesystem = new FakeFilesystem(); $this->deleteSet = new DeleteSet( $this->setRepository, $this->elementRepository, $this->filesystem, ); } public function testDeletesSetElementTreeAndManagedFiles(): void { $set = $this->createSet('set-icons/set.png'); $rootElement = $this->createElement( set: $set, parentElement: null, title: 'Root', iconImageUrl: 'set-icons/set.png', shortPdfPath: null, longPdfPath: null, ); $childElement = $this->createElement( set: $set, parentElement: $rootElement, title: 'Child', iconImageUrl: 'element-icons/child.png', shortPdfPath: 'element-pdfs/short/child.pdf', longPdfPath: 'element-pdfs/long/child.pdf', ); $grandchildElement = $this->createElement( set: $set, parentElement: $childElement, title: 'Grandchild', iconImageUrl: 'element-icons/grandchild.png', shortPdfPath: 'element-pdfs/short/grandchild.pdf', longPdfPath: 'element-pdfs/long/grandchild.pdf', ); $this->deleteSet->execute(new DeleteSetRequest(id: $set->getId())); $this->assertNull($this->setRepository->find($set->getId())); $this->assertNull( $this->elementRepository->find($rootElement->getId()), ); $this->assertNull( $this->elementRepository->find($childElement->getId()), ); $this->assertNull( $this->elementRepository->find($grandchildElement->getId()), ); $this->assertEqualsCanonicalizing([ 'set-icons/set.png', 'element-icons/child.png', 'element-pdfs/short/child.pdf', 'element-pdfs/long/child.pdf', 'element-icons/grandchild.png', 'element-pdfs/short/grandchild.pdf', 'element-pdfs/long/grandchild.pdf', ], $this->filesystem->deletedPaths); $this->assertSame( count($this->filesystem->deletedPaths), count(array_unique($this->filesystem->deletedPaths)), ); } public function testRequiresSetId(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('setId is required'); $this->deleteSet->execute(new DeleteSetRequest(id: null)); } public function testThrowsWhenSetIsMissing(): void { $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Set not found'); $this->deleteSet->execute(new DeleteSetRequest(id: 999)); } private function createSet(string $iconImageUrl): DomainSet { return $this->setRepository->create(new CreateSetDto( name: 'Set', description: 'Set description', iconImageUrl: $iconImageUrl, )); } private function createElement( DomainSet $set, ?Element $parentElement, string $title, ?string $iconImageUrl, ?string $shortPdfPath, ?string $longPdfPath, ): Element { return $this->elementRepository->create(new CreateElementDto( set: $set, title: $title, description: "$title description", iconImageUrl: $iconImageUrl, richText: '', shortPdfPath: $shortPdfPath, longPdfPath: $longPdfPath, youtubeUrl: null, parentElement: $parentElement, )); } }