承接 trinet/mezzio-test 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

trinet/mezzio-test

最新稳定版本:1.3.0

Composer 安装命令:

composer require trinet/mezzio-test

包简介

Testing helpers for mezzio projects

README 文档

README

Check Build

mezzio-test

mezzio-test provides classes and tools to help testing mezzio applications. Its API aims to be similar to laminas-test to ease migration from Laminas MVC to Mezzio.

The package is not bound to any testing framework as it does not do any assertions. Instead it just bootstraps the Container and Application based on your config file. Config file locations default to the mezzio-skeleton, but can be reconfigured.

Also, a TestConfigProvider is provided for loading custom testing configuration (custom database, custom container configuration, ...).

Usage

Instantiate the \Trinet\MezzioTest\MezzioTestEnvironment class in your test setup:

protected function setUp(): void
{
    parent::setUp();
    $this->mezzioApp = new MezzioTestEnvironment();
}

This will build your application container, bootstrap the mezzio Application (pipeline, routes) and registers a custom \Laminas\Stratigility\Middleware\ErrorHandler listener, which will just re-throw any exception. Thus, the native exception assertions can be used (eg. $this->expectException() in PHPUnit).

Currently, the Test environment offers three possibilities to dispatch a request:

  • dispatch(UriInterface|string $uri, ?string $method = null, array $params = [], array $headers = []): ResponseInterface: dispatch any URI with the given method (defaults to GET). $params will be used as query parameters for GET and as parsed body for POST requests.
  • dispatchRoute(string $routeName, array $routeParams = [], string $method = null, array $requestParams = [], array $headers = []): ResponseInterface: dispatch a given named route
  • dispatchRequest(ServerRequestInterface $request): ResponseInterface: dispatch a ServerRequestInterface

If your base directory is not at the default location, a constructor parameter can be given to MezzioTestEnvironment.

The container and router can also be retrieved with MezzioTestEnvironment->container() and ->router(), respectively.

Configuration

The \Trinet\MezzioTest\TestConfigProvider can be used to load additional config files used for testing. It will look for *testing.php, *testing.local.php, testing/*testing.php and testing/*testing.local.php in the config directory, which defaults to config/autoload/ in your project root, but can be configured to anything else.

To use it, call the loader when in testing mode in your config/config.php file to get an array of providers:

$providers = [
    \A\ConfigProvider::class,
    \B\ConfigProvider::class,
    // ...
];

if (getenv('APP_TESTING') !== false) {
    $providers = array_merge($providers, \Trinet\MezzioTest\TestConfigProvider::load());
}

$aggregator = new ConfigAggregator($providers, null, []);

or to use another config path:

$providers = [
    \A\ConfigProvider::class,
    \B\ConfigProvider::class,
    // ...
];

if (getenv('APP_TESTING') !== false) {
    $providers = array_merge($providers, \Trinet\MezzioTest\TestConfigProvider::load('custom/path'));
}

$aggregator = new ConfigAggregator($providers, null, []);

统计信息

  • 总下载量: 995
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固