test pdf use case

This commit is contained in:
Yisroel Baum 2026-06-26 08:13:46 +03:00
parent 208c683dac
commit b1bee8a16e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 165 additions and 0 deletions

View file

@ -0,0 +1,97 @@
<?php
namespace Tests\Unit\Element\UseCases;
use App\Element\UseCases\GetElementPdf\GetElementPdf;
use App\Element\UseCases\GetElementPdf\GetElementPdfRequest;
use App\Exceptions\NotFoundException;
use Tests\Fakes\FakeStoredFileReader;
use Tests\TestCase;
class GetElementPdfTest extends TestCase
{
private FakeStoredFileReader $storedFileReader;
private GetElementPdf $useCase;
protected function setUp(): void
{
$this->storedFileReader = new FakeStoredFileReader();
$this->useCase = new GetElementPdf($this->storedFileReader);
}
public function testReturnsShortPdfFile(): void
{
$this->storedFileReader->put(
'element-pdfs/short/baderech.pdf',
'short-pdf-bytes',
);
$result = $this->useCase->execute(new GetElementPdfRequest(
folder: 'short',
fileName: 'baderech.pdf',
));
$this->assertSame('short-pdf-bytes', $result->getContents());
$this->assertSame('baderech.pdf', $result->getFileName());
$this->assertSame('application/pdf', $result->getMimeType());
$this->assertSame(
['element-pdfs/short/baderech.pdf'],
$this->storedFileReader->readPaths,
);
}
public function testReturnsLongPdfFile(): void
{
$this->storedFileReader->put(
'element-pdfs/long/baderech-long.pdf',
'long-pdf-bytes',
);
$result = $this->useCase->execute(new GetElementPdfRequest(
folder: 'long',
fileName: 'baderech-long.pdf',
));
$this->assertSame('long-pdf-bytes', $result->getContents());
$this->assertSame('baderech-long.pdf', $result->getFileName());
$this->assertSame('application/pdf', $result->getMimeType());
$this->assertSame(
['element-pdfs/long/baderech-long.pdf'],
$this->storedFileReader->readPaths,
);
}
public function testInvalidFolderThrowsNotFound(): void
{
$this->expectException(NotFoundException::class);
$this->expectExceptionMessage('PDF not found');
$this->useCase->execute(new GetElementPdfRequest(
folder: 'archive',
fileName: 'baderech.pdf',
));
}
public function testInvalidFileNameThrowsNotFound(): void
{
$this->expectException(NotFoundException::class);
$this->expectExceptionMessage('PDF not found');
$this->useCase->execute(new GetElementPdfRequest(
folder: 'short',
fileName: '../baderech.pdf',
));
}
public function testMissingStorageFileThrowsNotFound(): void
{
$this->expectException(NotFoundException::class);
$this->expectExceptionMessage('PDF not found');
$this->useCase->execute(new GetElementPdfRequest(
folder: 'short',
fileName: 'missing.pdf',
));
}
}