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 7237e4d
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions tests/Unit/Service/TransmissionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,50 +85,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 +132,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 7237e4d

Please sign in to comment.