56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Model;
|
|
|
|
use App\Model\EmailPathAttachmentDto;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
|
|
|
class EmailPathAttachmentDtoTest extends TestCase
|
|
{
|
|
public function testAttachToAddsPathAttachment(): void
|
|
{
|
|
$tmpFile = tempnam(sys_get_temp_dir(), 'test_attachment_');
|
|
file_put_contents($tmpFile, 'dummy-pdf-content');
|
|
|
|
try {
|
|
$dto = new EmailPathAttachmentDto($tmpFile, 'invoice.pdf');
|
|
$email = new TemplatedEmail();
|
|
|
|
$dto->attachTo($email);
|
|
|
|
$attachments = $email->getAttachments();
|
|
$this->assertCount(1, $attachments);
|
|
$this->assertSame('invoice.pdf', $attachments[0]->getFilename());
|
|
$this->assertSame('application/pdf', $attachments[0]->getMediaType().'/'.$attachments[0]->getMediaSubtype());
|
|
} finally {
|
|
unlink($tmpFile);
|
|
}
|
|
}
|
|
|
|
public function testDefaultMimeTypeIsApplicationPdf(): void
|
|
{
|
|
$dto = new EmailPathAttachmentDto('/tmp/test.pdf', 'test.pdf');
|
|
|
|
$this->assertSame('application/pdf', $dto->getMimeType());
|
|
}
|
|
|
|
public function testCustomMimeType(): void
|
|
{
|
|
$dto = new EmailPathAttachmentDto('/tmp/test.csv', 'test.csv', 'text/csv');
|
|
|
|
$this->assertSame('text/csv', $dto->getMimeType());
|
|
}
|
|
|
|
public function testGettersReturnConstructorValues(): void
|
|
{
|
|
$dto = new EmailPathAttachmentDto('/var/uploads/file.pdf', 'document.pdf', 'application/pdf');
|
|
|
|
$this->assertSame('/var/uploads/file.pdf', $dto->getPath());
|
|
$this->assertSame('document.pdf', $dto->getName());
|
|
$this->assertSame('application/pdf', $dto->getMimeType());
|
|
}
|
|
}
|