atoum/blackfire-extension
Composer 安装命令:
composer require atoum/blackfire-extension
包简介
Write your Blackfire test suites with atoum
README 文档
README
blackfire-extension allows you to use blackfire assertions inside atoum.
The Blackfire PHP-SDK has a built-in PHPUnit integration. This extension does the same, but for atoum.
Example
Let's take this example.
namespace Tests\Units; use Example as TestedClass; use atoum; class Example extends atoum { public function testExemple() { $this ->blackfire ->assert('main.wall_time < 2s', "Temps d'execution") ->profile(function() { sleep(4); //just to make the test fail //some code to profile // ... //you also can run atoum assertions inside this callable //but beware, atoum's logic will also be profiled. $this->boolean(true)->isTrue(); }) ; } }
When running this test, the callback will be automatically instrumented and execute on Blackfire the assertions defined by the Configuration. If they fail, an atoum error will be displayed.The above example will have this output :
Install it
Install extension using composer:
composer require --dev atoum/blackfire-extension
Enable and configure the extension using atoum configuration file:
<?php // .atoum.php require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; $runner ->getExtension(mageekguy\atoum\blackfire\extension::class) ->setClientConfiguration(new \Blackfire\ClientConfiguration($_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN'])) ->addToRunner($runner) ;
Other examples
Define custom metrics
$this ->blackfire ->defineMetric(new \Blackfire\Profile\Metric("example_method_calls", "=Example::method")) ->assert("metrics.example_method_calls.count < 10") ->profile(function() { $testedClass = new TestedClass(); for ($i = 0; $i < 8; $i++) { $testedClass->method(); } }) ;
You can learn more about this on the custom metric's section of Blackfire documentation.
Pass your own profile configuration
$this ->given( $profileConfiguration = new \Blackfire\Profile\Configuration(), $profileConfiguration->setTitle('Profile configuration title'), $testedClass = new TestedClass() ) ->blackfire ->setConfiguration($profileConfiguration) ->assert("main.peak_memory < 10mb") ->profile(function() use ($testedClass) { $testedClass->method(); }) ;
You can learn more about this on the profile basic configurable's section of Blackfire documentation.
Pass a custom client
You can either pass the blackfire client in the .atoum.php config file (when loading the extension). In that case the client will be used in all the blackfire assertions. You also can load/overload it in the blackfire assert. For example:
$this ->given( $config = new \Blackfire\ClientConfiguration($_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN']); $client = new \Blackfire\Client($config); ) ->blackfire(client) ->assert('main.wall_time < 2s') ->profile(function() { //code to profile }) ;
Test filtering
To avoid running the test if the blackfire extension is not loaded, you can use the @extensions annotation.
/** * @extensions blackfire */ public function testExemple() { $this ->blackfire($this->getBlackfireClient()) ->defineMetric(new \Blackfire\Profile\Metric("example_method_calls", "=Example::method")) ->assert("metrics.example_method_calls.count < 10") ->profile(function() { $testedClass = new TestedClass(); for ($i = 0; $i < 8; $i++) { $testedClass->method(); } }) ; }
You can add this annotation on both the test method or the test class.
Then, when running the test, the classes/methods with this annotation will be skipped if the extension is not present/loaded:
Success (1 test, 0/1 method, 0 void method, 1 skipped method, 0 assertion)!
> There is 1 skipped method:
=> Tests\Units\Example::testExemple(): PHP extension 'blackfire' is not loaded
You also can use atoum's tags and the ruler extension to only run the blackfire tests.
Links
Licence
blackfire-extension is released under the MIT License. See the bundled LICENSE file for details.
atoum/blackfire-extension 适用场景与选型建议
atoum/blackfire-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「atoum」 「test」 「unit testing」 「blackfire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atoum/blackfire-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atoum/blackfire-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atoum/blackfire-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
atoum telemetry reports extension
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
Testing Suite For Lumen like Laravel does.
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Automatically run atoum's loop mode on file change
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-05
