dxw / codeception-notify-module
适用于使用 UK Notify 的应用程序的验收测试的 Codeception 模块
Requires
- php: >=7.0
- mcustiel/phiremock-codeception-extension: ^1.6
Requires (Dev)
This package is auto-updated.
Last update: 2022-10-05 13:20:31 UTC
README
一个 Codeception 模块,扩展了 phiremock-codeception-extension,用于测试调用 UK Notify 的应用程序。
Phiremock 扩展作为 Composer 依赖项加载,因此无需单独安装。
安装
composer require --dev dxw/codeception-notify-module
如何使用
目前该模块仅测试对 Notify 电子邮件端点的请求。
设置
在您的 codeception.yml 中配置 Phiremock 扩展以启动 Phiremock 服务器。您需要修改您的 Notify 配置,以便在测试环境中它将击中此模拟服务器。
extensions: enabled: - \Codeception\Extension\Phiremock config: \Codeception\Extension\Phiremock: listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086 bin_path: ../vendor/bin # defaults to codeception_dir/../vendor/bin logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir debug: true # defaults to false startDelay: 1 # default to 0 expectations_path: /my/expectations/path
然后,在您的套件配置文件中启用 Notify 模块,并配置它以便知道如何与模拟服务器通信
modules: enabled: - \dxw\Codeception\Module\Notify: host: 127.0.0.1 port: 18080 resetBeforeEachTest: true # recommend setting this to true for predictable results
使用
所有由 Phiremock 模块 定义的常规方法都可用。在这些方法之上,还有一些特定的 Notify 方法
expectEmailRequestWithSuccessResponse
允许您指定对电子邮件端点的请求应该收到 200 响应。请注意,如果此请求未执行,则测试不会失败 - 这只是告诉模拟服务器如果请求执行了,则应提供什么响应。
$I->expectEmailRequestWithSuccessResponse();
您还可以指定响应体应该是什么(以 JSON 格式)
$I->expectEmailRequestWithSuccessResponse('{"response":"body"}');
expectEmailRequestWithFailureResponse
允许您指定对电子邮件端点的请求应该收到 401 响应。如果您以相同的方式处理所有失败响应,则可以使用此方法。
$I->expectEmailRequestWithFailureResponse();
您还可以指定应返回的错误代码和正文,例如
$I->expectEmailRequestWithFailureResponse(403, '{"errors":[{"error":"AuthError", "message":"Invalid token"}]}');
请注意,正文必须符合 AlphaGov\Notifications\Exception\ApiException 类 预期的格式,否则 Notify 客户端将发生错误。
getRecipientEmailAddresses
返回一个按时间顺序排列的电子邮件地址数组,其中包含已发送的所有电子邮件地址。
$recipients = $I->getRecipientEmailAddresses();
seeLastEmailWasSentTo
验证最后请求是否发送到您提供的电子邮件地址。
$I->seeLastEmailWasSentTo('address@domain.com');
seeNotifyReceivedEmailRequests
验证任何电子邮件请求是如何发送到 Notify 的。
$I->seeNotifyReceivedEmailRequests(5)
开发
安装依赖项
composer install
运行测试
vendor/bin/codecept run unit
运行代码检查工具
vendor/bin/php-cs-fixer fix