Compare commits

..

3 Commits

Author SHA1 Message Date
李东云
768f2d79c0 chore(release): 1.0.0-beta.7 2025-03-03 09:59:24 +00:00
李东云
225bdedd23 feat(EmailService): 添加邮件附件功能并更新单元测试
- 在 EmailService 类的 sendHtml 方法中添加了附件处理逻辑
- 更新了 EmailServiceTest 单元测试,增加了附件发送的测试用例
- 优化了测试用例的结构,提高了可读性和可维护性
2025-03-03 09:57:04 +00:00
李东云
aaa4382ff2 build(devcontainer): 添加 Hyperf 开发套件核心配置文件
- 新增 devcontainer.json 配置文件,用于 Hyperf 框架的开发环境
- 配置了基础设置、挂载点、容器生命周期管理等
- 集成了多个 Visual Studio Code 扩展,提升开发效率
2025-03-03 09:32:35 +00:00
6 changed files with 134 additions and 12 deletions

View File

@@ -0,0 +1,49 @@
{
"name": "Hyperf Development Kit Core Dev Container",
"image": "harbor.luxcreo.cn/library/hyperf:8.1-swoole",
// 基础配置
"workspaceFolder": "/srv/www", // 对应 --workdir
"workspaceMount": "source=${localWorkspaceFolder},target=/srv/www,type=bind", // 主工作区挂载
// 附加挂载
"mounts": [
"source=${env:HOME}/.ssh,target=/root/.ssh,type=bind", // SSH 密钥挂载
"source=${env:HOME}/.gitconfig,target=/root/.gitconfig,type=bind" // SSH 密钥挂载
],
// 容器生命周期
"shutdownAction": "stopContainer", // 类似 --rm 的清理行为
"updateRemoteUserUID": true, // 确保用户 ID 同步
// 保留的必要 runArgs
"runArgs": [
"--pull=always", // 强制拉取最新镜像
"--name=hdk-core" // 容器命名(需保持唯一性)
],
// 初始化命令
"postCreateCommand": "echo 'Container initialized!'",
"customizations": {
"vscode": {
"extensions": [
"rid9.datetime",
"MS-CEINTL.vscode-language-pack-zh-hans",
"ms-azuretools.vscode-docker",
"janisdd.vscode-edit-csv",
"onecentlin.laravel-blade",
"DavidWang.ini-for-vscode",
"bmewburn.vscode-intelephense-client",
"mechatroner.rainbow-csv",
"Alibaba-Cloud.tongyi-lingma",
"atommaterial.a-file-icon-vscode",
"ParthR2031.colorful-comments",
"vincaslt.highlight-matching-tag",
"xabikos.JavaScriptSnippets",
"shufo.vscode-blade-formatter",
"dansysanalyst.pest-snippets",
"m1guelpf.better-pest",
"xoronic.pestfile",
"xdebug.php-debug",
"golang.go",
"cweijan.vscode-typora",
"ciceroisback.loam"
]
}
}
}

View File

@@ -1,4 +1,16 @@
# 版本更新日志
## [1.0.0-beta.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2025-03-03)
### 📦‍ Build System | 打包构建
* **devcontainer:** 添加 Hyperf 开发套件核心配置文件 ([aaa4382](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/aaa4382ff2c5105bc362777f62156b8383b67ed8))
### ✨ Features | 新功能
* **EmailService:** 添加邮件附件功能并更新单元测试 ([225bded](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/225bdedd23b1655d5fb7260838fc8c60db5d8f9f))
## [1.0.0-beta.6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2024-12-06)

View File

@@ -1 +1 @@
1.0.0-beta.6
1.0.0-beta.7

View File

@@ -130,5 +130,5 @@
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.0.0-beta.6"
"version": "1.0.0-beta.7"
}

View File

@@ -130,6 +130,8 @@ class EmailService
string $html,
array $cc = [],
array $bcc = [],
array $attachmentPaths = [],
array $attachments = [],
int $priority = Email::PRIORITY_NORMAL
): bool {
$email = (new Email())
@@ -141,6 +143,22 @@ class EmailService
->subject($subject)
->html($html);
foreach ($attachmentPaths as $attachmentPath) {
if (is_string($attachmentPath)) {
$email = $email->attachFromPath($attachmentPath);
} else {
$email = $email->attachFromPath($attachmentPath['path'], $attachmentPath['name'] ?? null, $attachmentPath['mimeType'] ?? null);
}
}
foreach ($attachments as $attachment) {
if (is_string($attachment)) {
$email = $email->attach($attachment);
} else {
$email = $email->attach($attachment['content'], $attachment['name'] ?? null, $attachment['mimeType'] ?? null);
}
}
$this->mailer->send($email);
return true;

View File

@@ -1,4 +1,5 @@
<?php
/**
* EmailServiceTest.php@HDK-Core
*
@@ -9,15 +10,19 @@
namespace Singularity\HDK\Test\Core\Service;
use PharIo\Manifest\Email;
use Singularity\HDK\Core\Service\EmailService;
use Symfony\Component\Mailer\Exception\TransportException;
$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);
use function Hyperf\Support\make;
it('assertions that send HTML is available', function () use ($email) {
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',
@@ -26,9 +31,15 @@ it('assertions that send HTML is available', function () use ($email) {
HTML
);
expect($result)->toBeTrue();
})->skip();
});
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]);
it('assertions that send Text is available', function () use ($email) {
$result = $email->sendText(
'dongyun.li@luxcreo.ai',
'HDK Unit Test Text',
@@ -37,9 +48,15 @@ it('assertions that send Text is available', function () use ($email) {
Text
);
expect($result)->toBeTrue();
})->skip();
});
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]);
it('assertions Error Receiver can be catch', function () use ($email) {
try {
$email->sendHtml(
'unknown@luxcreo.ai',
@@ -62,4 +79,30 @@ Text
} catch (TransportException $t) {
expect($t->getCode())->toBe(554);
}
})->skip('会报错必须运行在协程环境下');
});
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();