appeltaert/phpunit-assertion-message 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

appeltaert/phpunit-assertion-message

Composer 安装命令:

composer require --dev appeltaert/phpunit-assertion-message

包简介

Enhanced PHPUnit Assertion Messages - Debug assertions without creating a mess.

README 文档

README

PHPUnit Assertion Message Build Status SensioLabsInsight

composer require --dev appeltaert/phpunit-assertion-message

Usage

  1. Simply wrap whatever message you normally pass to assertions in a new PAM(string $message, [mixed $context,...]) instance.
  2. Run phpunit with --debug

$context can be basically be anything, for now there's only explicit support for Symfony Response and Request objects, but as a final resort a var flattening processor will take over to basically make anything readable if no processor can handle your context.

Before

This will turn this occasional mess while debugging.

$client->enableProfiler();
$response = $client->getResponse();

$this->assertTrue($response->isSuccessful(), "My message");
There was 1 failure:
    
1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex
My message

// wtf is going on
// $this->assertTrue($client->getResponse()->isSuccessful())
// $collector = $profiler->getCollector()..
// var_dump($collector->...);
// echo $response->getContent();
// var_dump($response->headers->all();
// die.. die.. die..

After

Into this.

$client->enableProfiler();
$response = $client->getResponse();

$this->assertTrue($response->isSuccessful(), 
    new PAM("My message", [$response, $profiler->getCollector('request')]));
There was 1 failure:

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex
My message

HTTP response:         Code: 200
               Content-type: text/html; charset=UTF-8
                    Cookies: 0: qwer=qewrqwer; path=/; httponly
                    
Request profile:      Format: html
                  StatusText: OK
                       Route: app_router_index
                  StatusCode: 200
                 ContentType: text/html; charset=UTF-8
                    PathInfo: /router/

How it works

Processors

All context passed is handled by a chain of Processors. The first one to accept the context wins. The processors are then printed by a Printer. The default printer Plain dumps everything into human-readable blocks.

Symfony Response object

$response = $client->getResponse();
$this->assertTrue($response->isSuccessful(), new PAM("My message", [$response]));
HTTP response:      Code: 500
                 Headers:  content-type: ["text\/html; charset=UTF-8"]
                          cache-control: ["no-cache, private"]
                                   date: ["Fri, 23 Feb 2018 21:12:32 GMT"]
                          x-debug-token: ["771d20"]
               Exception: qewr (500 Internal Server Error)
                   

Symfony request profiler

$this->assertSame(
    Response::HTTP_OK,
    $client->getResponse()->getStatusCode(),
    new PAM(sprintf('The %s public URL loads correctly.', $url), [$client->getProfile()->getCollector('request')])
);
Request profile:            Format: html
                             Route: blog_index
                        StatusText: Internal Server Error
                        StatusCode: 500
                       ContentType: text/html; charset=UTF-8
                          PathInfo: /en/blog/
                            Method: GET
                            Locale: en
                       RouteParams:    page: 1
                                    _format: html
                                    _locale: en
                 SessionAttributes: key: val
                   SessionMetaData:   Created: Fri, 23 Feb 18 22:12:31 +0100
                                    Last used: Fri, 23 Feb 18 22:12:31 +0100
                                     Lifetime: 0
                            Action: AppBundle\Controller\BlogController::indexAction

Array

$someArray = [];
$this->assertArrayHasKey("test", $array, new PAM("My message", [
    'qwerqwer' => 'qwerqewr', ['qwerqewr', 'qwerqwer']
]));
Array: qwerqwer: qwerqewr
              0: 0: qwerqewr
                 1: qwerqwer

Config

Printer

At the moment there is only one printer, Plain.

Statically set all options

PAM::setDefaults($processors, $printer, $env);

Overriding the environment

$env = new Env($debug = null, $verbose = null, $supportsColors = null);
PAM::setDefaults([], null, $env);

roadmap

v1.1

processors

  • more symfony
  • move them to separate suggested repos
  • make them pluggable

printer

  • distinctive dumps based on env, more info --verbose, less without
  • detect interactive terminal(for colored output f.e.), also check ansi arguments.
  • posix_isatty, XTERM check?

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固