namelesscoder / phpunit-xhprof
此包的最新版本(1.0.0)没有提供许可证信息。
通过PHP特性实现XHProf与PHPUnit的集成
1.0.0
2015-09-09 21:57 UTC
Requires
- ext-pdo_sqlite: *
- lox/xhprof: dev-master
- mikey179/vfsstream: *
- phpunit/phpunit: ^4.8
- satooshi/php-coveralls: *
This package is auto-updated.
Last update: 2024-09-12 03:53:08 UTC
README
提供单个特性,可用于测试用例中分析性能数据,并根据这些数据在测试中进行断言。简而言之,允许调用任意数量的代码并分析结果,例如,了解某个方法或类被使用了多少次,使用的类和函数总数,CPU和内存使用情况,类A到类B的调用等。
这与PHPUnit的$this->at($index)
、$this->exactly()
和其他期望方法类似,但它不是通过模拟来实现,而是通过性能分析。因此,它可以涵盖任何数量和复杂性的逻辑,并能够,例如,告诉类A调用类B的方法X的总次数。
此外,还提供了支持CPU和内存使用情况性能分析的能力。然而,这里有一个警告。
注意事项
注意:您可以在性能分析结果中包含CPU时间和内存使用情况,但是当您的测试预期将在多个不同性能的平台执行时,您可能需要避免这样做,并坚持使用调用方法数(或相对度量,例如,总分析时间的百分比,但即使是这样,平台差异也可能导致偏差/失败)。
用法
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' ); }
这就是全部内容。您可以在xhprof文档中查看可能的标志和选项,以及$profile
数组的结构示例。