97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?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',
|
|
));
|
|
}
|
|
}
|