diff --git a/tests/Unit/Service/TransmissionServiceTest.php b/tests/Unit/Service/TransmissionServiceTest.php index 202240ef48..1d232abf06 100644 --- a/tests/Unit/Service/TransmissionServiceTest.php +++ b/tests/Unit/Service/TransmissionServiceTest.php @@ -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); @@ -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() {