setRepository = new FakeSetRepository(); $this->filesystem = new FakeFilesystem(); } public function testUpdatesOnlyIconAndDeletesOldIcon(): void { $set = $this->createSet(); $updateIconImage = new UpdateIconImage( $this->setRepository, $this->filesystem, ); $updatedSet = $updateIconImage->execute(new UpdateIconImageRequest( id: $set->getId(), fileContents: 'image contents', fileOriginalName: 'updated.png', fileMimeType: 'image/png', fileSizeBytes: 13, )); $this->assertSame($set->getName(), $updatedSet->getName()); $this->assertSame( $set->getDescription(), $updatedSet->getDescription(), ); $this->assertSame( 'set-icons/fake-updated.png', $updatedSet->getIconImageUrl(), ); $this->assertCount(1, $this->filesystem->uploads); $this->assertSame('set-icons', $this->filesystem->uploads[0]['folder']); $this->assertSame([ 'set-icons/original.png', ], $this->filesystem->deletedPaths); } public function testRejectsMissingFile(): void { $set = $this->createSet(); $updateIconImage = new UpdateIconImage( $this->setRepository, $this->filesystem, ); $this->expectException(BadRequestException::class); $this->expectExceptionMessage('icon image is required'); $updateIconImage->execute(new UpdateIconImageRequest( id: $set->getId(), fileContents: null, fileOriginalName: null, fileMimeType: null, fileSizeBytes: null, )); } public function testRejectsInvalidMimeType(): void { $set = $this->createSet(); $updateIconImage = new UpdateIconImage( $this->setRepository, $this->filesystem, ); $this->expectException(BadRequestException::class); $this->expectExceptionMessage( 'icon image must be a jpeg, png or webp image', ); $updateIconImage->execute(new UpdateIconImageRequest( id: $set->getId(), fileContents: 'image contents', fileOriginalName: 'updated.gif', fileMimeType: 'image/gif', fileSizeBytes: 13, )); } private function createSet(): DomainSet { return $this->setRepository->create(new CreateSetDto( name: 'Original Set', description: 'Original set description', iconImageUrl: 'set-icons/original.png', )); } }