martinsr / phiremock-codeception-extension-laravel-11
Phiremock 的 Codeception 扩展。允许对 HTTP 请求进行远程服务的存根。
Requires
- php: ^8.2
- codeception/codeception: ^5.0
- symfony/process: ^v7.0.4
Requires (Dev)
- codeception/module-phpbrowser: ^3.0
- codeception/module-rest: ^3.0
- guzzlehttp/guzzle: ^7.8.1
- mcustiel/phiremock-server: ^1.0
Suggests
- guzzlehttp/guzzle: Version 6 to execute phiremock-server as default
- mcustiel/phiremock-server: As a dev-requirement. Allows the extension to start phiremock automatically from vendor/bin
This package is auto-updated.
Last update: 2024-09-20 19:55:41 UTC
README
Codeception 扩展,使与 Phiremock 服务器 一起工作更加简单。它允许在执行套件之前启动 Phiremock 服务器,并在套件结束时停止它。
安装
Composer
"require-dev": { "mcustiel/phiremock-codeception-extension": "^2.0" }
可选地,如果您想在依赖项之间安装 Phiremock 服务器,则可以安装 Phiremock 服务器。如果没有,您需要指定配置中 phiremock 的路径。
"require-dev": { "mcustiel/phiremock-codeception-extension": "^2.0", "mcustiel/phiremock-server": "^1.0", "guzzlehttp/guzzle": "^6.0" }
Phiremock 服务器已作为可选依赖项添加,以便您可以从 phar 文件、全局 composer 依赖项或 docker 容器中运行它,而不将其作为项目依赖项。
配置
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 wait_until_ready: true # defaults to false wait_until_ready_timeout: 15 # (seconds) defaults to 30 wait_until_ready_interval: 100 # (microseconds) defaults to 50000 expectations_path: /my/expectations/path # defaults to tests/_expectations server_factory: \My\FactoryClass # defaults to 'default' extra_instances: [] # deaults to an empty array suites: [] # defaults to an empty array certificate: /path/to/cert # defaults to null certificate_key: /path/to/cert-key # defaults to null cert_passphrase: 'my-pass' # defaults to null
注意:由于 Codeception 版本 2.2.7,扩展配置可以直接添加到套件配置文件中。这将避免每次套件运行时都启动 phiremock。
参数
listen
指定 phiremock 必须监听请求的接口和端口。
默认 0.0.0.0:8086
bin_path
Phiremock 服务器“二进制”文件所在的路径。例如,您可以指向文件系统中 phar 的位置。
默认: codeception_dir/../vendor/bin/phiremock
logs_path
写入输出的路径。
默认: codeception 的测试输出目录
debug
是否将调试数据写入日志文件。
默认: false
start_delay
Phiremock 服务器启动后等待的时间,然后运行测试(用于给 Phiremock 服务器启动时间)
默认 0
wait_until_ready
这是 start_delay 的更健壮的替代方案。它将在运行测试之前检查 Phiremock 服务器是否实际上正在运行。注意:它依赖于通过 composer 安装的 Phiremeock 客户端(它用于检查 Phiremock 服务器状态)。
默认: false
wait_until_ready_timeout
只有在 wait_until_ready 设置为 true 时才会使用。您可以指定多少秒后停止检查 Phiremock 服务器是否正在运行。
默认 30
expectations_path
指定一个目录以搜索定义默认要加载的期望的 json 文件。
默认: codecption_dir/_expectations
certificate
证书文件的路径,以允许 phiremock-server 监听安全的 https 连接。
默认: null。这意味着 phiremock 只会监听未加密的 http 连接。
certificate-key
证书密钥文件的路径。
默认: null。
cert-passphrase
证书密码文件的路径,用于加密证书(如果加密则需要)。
默认: null。这意味着不会执行基于密码的解密。
suites
指定必须执行 phiremock-server 的套件列表。
默认: [] 空数组,意味着 phiremock 将为每个套件执行。
extra_instances
允许指定更多要运行的 phiremock-server 实例。如果您想,例如,运行一个监听 http 连接的实例和一个监听 https 连接的实例,这很有用。每个实例都有自己的配置,并且可以分别运行不同的套件。
默认: [] 空数组,意味着没有配置额外的 phiremock-server 实例。
示例
extensions: enabled: - \Codeception\Extension\Phiremock config: \Codeception\Extension\Phiremock: listen: 127.0.0.1:18080 debug: true expectations_path: /my/expectations/path-1 suites: - acceptance extra_instances: - listen: 127.0.0.1:18081 debug: true start_delay: 1 expectations_path: /my/expectations/path-2 suites: - acceptance - api certificate: /path/to/cert certificate_key: /path/to/cert-key cert_passphrase: 'my-pass'
server_factory
指定一个扩展 \Mcustiel\Phiremock\Server\Factory\Factory
的工厂类。如果您想提供自己的 PSR,则很有用。这仅在您将 phiremock 作为本地依赖项安装到 composer 文件中时才有效。
默认: default
示例: 如果您在 composer.json 中这样做
"require-dev": { "mcustiel/phiremock-codeception-extension": "v2.0", "mcustiel/phiremock-server": "^1.0", "guzzlehttp/guzzle": "^7.0"
您可以通过以下方式创建一个工厂
<?php namespace My\Namespace; use GuzzleHttp; use Mcustiel\Phiremock\Server\Factory\Factory; use Psr\Http\Client\ClientInterface; class FactoryWithGuzzle7 extends Factory { public function createHttpClient(): ClientInterface { return new GuzzleHttp\Client(); } }
并在扩展配置中提供该类的完全限定命名空间
enabled: - \Codeception\Extension\Phiremock config: \Codeception\Extension\Phiremock: server_factory: \My\Namespace\FactoryWithGuzzle7
另请参阅
- Phiremock 服务器: https://github.com/mcustiel/phiremock-server
- Phiremock Codeception 模块: https://github.com/mcustiel/phiremock-codeception-module