Skip to content

Commit

Permalink
test: update attachment tests to avoid deprecation warning
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Sep 9, 2024
1 parent e3524c8 commit 39713c5
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions tests/Unit/Service/TransmissionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
use OCA\Mail\Exception\AttachmentNotFoundException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Exception\SmimeSignException;
use OCA\Mail\Model\Message;
use OCA\Mail\Service\Attachment\AttachmentService;
use OCA\Mail\Service\GroupsIntegration;
use OCA\Mail\Service\SmimeService;
use OCA\Mail\Service\TransmissionService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\SimpleFS\InMemoryFile;
use OCP\Files\SimpleFS\ISimpleFile;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -85,50 +83,43 @@ public function testGetAttachments() {
$this->assertEquals($expected, $actual);
}

public function testHandleAttachment() {
$id = 1;
$expected = [
'type' => 'local',
'id' => $id
];
[$localAttachment, $file] = [
new LocalAttachment(),
$this->createMock(ISimpleFile::class)
];
$message = $this->createMock(Message::class);
public function testHandleAttachment(): void {
$mailAccount = new MailAccount();
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

$attachment = new LocalAttachment();
$attachment->setFileName('test.txt');
$attachment->setMimeType('text/plain');

$file = new InMemoryFile(
'test.txt',
"Hello, I'm a test file."
);

$this->attachmentService->expects(self::once())
->method('getAttachment')
->willReturn([$localAttachment, $file]);
->willReturn([$attachment, $file]);
$this->logger->expects(self::never())
->method('warning');

$this->transmissionService->handleAttachment($account, $expected);
$part = $this->transmissionService->handleAttachment($account, ['id' => 1, 'type' => 'local']);

$this->assertEquals('test.txt', $part->getContentTypeParameter('name'));
}

public function testHandleAttachmentNoId() {
$attachment = [[
'type' => 'local',
]];
$message = $this->createMock(Message::class);
$account = new Account(new MailAccount());
public function testHandleAttachmentNoId(): void {
$mailAccount = new MailAccount();
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

$this->logger->expects(self::once())
->method('warning');

$this->transmissionService->handleAttachment($account, $attachment);
$this->transmissionService->handleAttachment($account, ['type' => 'local']);
}

public function testHandleAttachmentNotFound() {
$attachment = [
'id' => 1,
'type' => 'local',
];

$message = $this->createMock(Message::class);
public function testHandleAttachmentNotFound(): void {
$mailAccount = new MailAccount();
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);
Expand All @@ -139,7 +130,7 @@ public function testHandleAttachmentNotFound() {
$this->logger->expects(self::once())
->method('warning');

$this->transmissionService->handleAttachment($account, $attachment);
$this->transmissionService->handleAttachment($account, ['id' => 1, 'type' => 'local']);
}

public function testGetSignMimePart() {
Expand Down

0 comments on commit 39713c5

Please sign in to comment.