承接 namelesscoder/phpunit-xhprof 相关项目开发

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

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

namelesscoder/phpunit-xhprof

最新稳定版本:1.0.0

Composer 安装命令:

composer require namelesscoder/phpunit-xhprof

包简介

XHProf / PHPUnit integration via PHP Trait for test cases

README 文档

README

Build Status Coverage Status

Provides a single Trait that can be used in your test cases to analyse profiling data and make assertions based on it in your test. In short, allows calling any amount of code and analysing the result to know for example how many times a certain method or class was used, the total number of classes and functions used, CPU and memory usage, calls from class A to class B and more.

You can view this much like an extended version of the $this->at($index) and $this->exactly() and other expectation methods of PHPUnit: it allows you to assert much the same but does so not by using mocks but by profiling. It can therefore cover any amount and complexity of logic and still be able to, for example, tell how many total times class A called method X on class B.

In addition to this comes the ability to support CPU and memory usage profiling. There is, however, a warning along with this.

Caveat

Note: you can include both CPU time and memory use in the profiling results, however, when your tests are expected to execute on multiple platforms of varying potency you should probably avoid this and stick to number of methods called (or a relative measure, e.g. percent of total profiled time, but even so platform differences may cause skew/failure).

Usage

public function testSomething() {
    // Profile only a specific scope plus a single
    // related function "myfunction". The result
    // will return everything that happens inside
    // any class of the defined scope, plus every
    // call to "myfunction" regardless of where the
    // function is called. You can find the syntax
    // of profile keys in the xhprof documentation.
    $methods = array(
        '/^Vendor\\Namespace\\Scope\\.+/',
        '/.+myfunction$'
    );
    $closure = function() use $foo, $bar {
        // do something that gets profiled. We have
        // already created and prepped our instances
        // so we don't profile that part of the code.
        $foo->doThatWith($bar);
    }
    $profile = $this->profileClosure($closure, $methods);
    $this->assertLessThan(
        10,
        $profile['Vendor\\Class::funcA==>Vendor\\Class::funcB']['ct'],
        'Method funcB was called from funcA more than expected 10 times'
    );
}

And that's about it. You can consult the xhprof documentation for possible flags and options, as well as examples of the structure of the $profile array.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-09-09