test pdf use case
This commit is contained in:
parent
208c683dac
commit
b1bee8a16e
3 changed files with 165 additions and 0 deletions
97
backend/tests/Unit/Element/UseCases/GetElementPdfTest.php
Normal file
97
backend/tests/Unit/Element/UseCases/GetElementPdfTest.php
Normal 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',
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue