darkmatus / phiremock-codeception-extension
Phiremock 的 Codeception 扩展。允许对 HTTP 请求的远程服务进行模拟。
Requires
- php: ^8.1
- codeception/codeception: >=5.0.x-dev
- codeception/module-asserts: ^3.0.0
- codeception/module-phpbrowser: ^3.0.0
- symfony/process: >=v6
Requires (Dev)
- codeception/module-rest: ^3.0
- guzzlehttp/guzzle: ^7.0
- 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
- dev-master
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v2.0.0-beta.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-feature/49
- dev-issues/7
- dev-php8
- dev-feature/multiple-instances
- dev-feature/secure
- dev-feature/select-suites
- dev-version-1.x
- dev-version-2.x
- dev-issue/21
- dev-develop
This package is auto-updated.
Last update: 2024-09-11 13:25:26 UTC
README
Codeception 扩展,使与 Phiremock 服务器 的协作更加便捷。它允许在执行套件之前启动 Phiremock 服务器,并在套件结束时停止它。
安装
Composer
"require-dev": { "mcustiel/phiremock-codeception-extension": "^2.0" }
可选地,如果您想在依赖项中安装 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文件中时才有效。
默认值:默认
示例:如果这在您的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 Server: https://github.com/mcustiel/phiremock-server
- Phiremock Codeception Module: https://github.com/mcustiel/phiremock-codeception-module