mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 07:15:06 +08:00
- 在 EmailService 类的 sendHtml 方法中添加了附件处理逻辑 - 更新了 EmailServiceTest 单元测试,增加了附件发送的测试用例 - 优化了测试用例的结构,提高了可读性和可维护性
109 lines
3.1 KiB
PHP
109 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* EmailServiceTest.php@HDK-Core
|
|
*
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
* Powered by PhpStorm
|
|
* Created on 2022/12/20
|
|
*/
|
|
|
|
namespace Singularity\HDK\Test\Core\Service;
|
|
|
|
use PharIo\Manifest\Email;
|
|
use Singularity\HDK\Core\Service\EmailService;
|
|
use Symfony\Component\Mailer\Exception\TransportException;
|
|
|
|
use function Hyperf\Support\make;
|
|
|
|
|
|
it('assertions that send HTML is available', function () {
|
|
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
|
$mail_sender_name = 'LuxCreo';
|
|
$mail_sender = 'account@luxcreo.ai';
|
|
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
|
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
|
$result = $email->sendHtml(
|
|
'dongyun.li@luxcreo.ai',
|
|
'HDK Unit Test HTML',
|
|
<<<HTML
|
|
<h1>Hello, World!</h1>
|
|
HTML
|
|
);
|
|
expect($result)->toBeTrue();
|
|
});
|
|
|
|
it('assertions that send Text is available', function () {
|
|
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
|
$mail_sender_name = 'LuxCreo';
|
|
$mail_sender = 'account@luxcreo.ai';
|
|
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
|
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
|
|
|
$result = $email->sendText(
|
|
'dongyun.li@luxcreo.ai',
|
|
'HDK Unit Test Text',
|
|
<<<Text
|
|
<h1>Hello, World!</h1>
|
|
Text
|
|
);
|
|
expect($result)->toBeTrue();
|
|
});
|
|
|
|
it('assertions Error Receiver can be catch', function () {
|
|
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
|
$mail_sender_name = 'LuxCreo';
|
|
$mail_sender = 'account@luxcreo.ai';
|
|
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
|
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
|
|
|
try {
|
|
$email->sendHtml(
|
|
'unknown@luxcreo.ai',
|
|
'HDK Unit Test',
|
|
<<<HTML
|
|
<h1>Hello, World!</h1>
|
|
HTML
|
|
);
|
|
} catch (TransportException $t) {
|
|
expect($t->getCode())->toBe(554);
|
|
}
|
|
try {
|
|
$email->sendText(
|
|
'unknown@luxcreo.ai',
|
|
'HDK Unit Test',
|
|
<<<Text
|
|
<h1>Hello, World!</h1>
|
|
Text
|
|
);
|
|
} catch (TransportException $t) {
|
|
expect($t->getCode())->toBe(554);
|
|
}
|
|
});
|
|
|
|
it('should can contain attachment', function () {
|
|
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
|
$mail_sender_name = 'LuxCreo';
|
|
$mail_sender = 'account@luxcreo.ai';
|
|
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
|
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
|
|
|
$email->sendHtml(
|
|
'dongyun.li@luxcreo.ai',
|
|
'HDK Unit Test HTML',
|
|
<<<HTML
|
|
<h1>Hello, World!</h1>
|
|
HTML,
|
|
[],
|
|
[],
|
|
[
|
|
[
|
|
'path' => __DIR__ . '/../../README.md',
|
|
'name' => 'README.md',
|
|
'mimeType' => 'text/markdown',
|
|
],
|
|
],
|
|
[]
|
|
);
|
|
})->only();
|