Faster Xdebug coverage analysis
Warren Seymour
Lead Developer, Radify
warren@radify.io
@woogoose
Why?
- Determine how meaningful your tests are.
- What use are your tests if they don't hit critical areas?
- Identify trends over time (new, untested code)
How?
- Record lines/statements actually covered during test run
- Collected & processed by Xdebug
- Supported by all good test runners
"Now I am become Xdebug, the destroyer of test times."
[video interlude]
Symfony2
-
03m50s (no coverage)
-
18m44s (--coverage-text)
-
Automated builds become painful
-
Good luck getting developers to measure locally
"Learn how a software company reduced their test coverage times with one weird old tip"
Enter Kahlan
composer require crysalead/kahlan
More than just a test runner
- rSpec-style testing framework
- Uses Xdebug to gather coverage data
- Has its own analyser; faster than Xdebug's
kahlan-config.php
- Powerful AOP workflow
- Integrate and invoke multiple test runners
- ... disable Kahlan's runner entirely!
- Gather coverage for all
- Report as a one or many metrics
Disable JIT & Kahlan Specs
<?php
Filter::register('symfony.disable', function($chain) {
return false;
});
Filter::apply($this, 'interceptor', 'symfony.disable');
Filter::apply($this, 'load', 'symfony.disable');
Configure Coverage
<?php
Filter::register('symfony.coverage', function($chain) {
$coverage = new Coverage([
'verbosity' => 1,
'driver' => new Xdebug(),
'path' => [
'src'
],
'exclude' => ['*/Tests/*']
]);
$reporters = $this->reporters();
$reporters->add('coverage', $coverage);
return $reporters;
});
Filter::apply($this, 'coverage', 'symfony.coverage');
Configure PHPUnit
<?php
Filter::register('symfony.run', function($chain) {
$coverage = $this->reporters()->get('coverage');
$coverage->before();
PHPUnit_TextUI_Command::main(false);
$coverage->after();
$coverage->stop();
});
Filter::apply($this, 'run', 'symfony.run');
Let's Rock!
[another video interlude]
Kahlan
+ PHPUnit
+ Coverage
- 4m23s (~30s penalty)
- Coffee break vs. Lunch break
- Full coverage on every build
Resources
- Symfony Example
- Kahlan
- Radify Blog
Thanks for listening!
[ question time ]
Faster Xdebug coverage analysis
By Warren Seymour
Faster Xdebug coverage analysis
- 3,637