Skip to content

Instantly share code, notes, and snippets.

@jakzal
Created October 19, 2011 14:47
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jakzal/1298503 to your computer and use it in GitHub Desktop.
Save jakzal/1298503 to your computer and use it in GitHub Desktop.
Running Behat in PHPUnit to calculate code coverage
<?php
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Behat\BehatBundle\Command\BehatCommand;
class BehatTest extends KernelAwareTest
{
/**
* @group behat
*/
public function testThatBehatScenariosMeetAcceptanceCriteria()
{
try {
$input = new ArrayInput(array('behat', '-e' => 'test', '--format' => 'progress'));
$output = new ConsoleOutput();
$application = new Application($this->kernel);
$command = new BehatCommand('behat');
$command->setApplication($application);
$result = $command->run($input, $output);
$this->assertEquals(0, $result);
} catch (\Exception $exception) {
$this->fail($exception->getMessage());
}
}
}
@lunetics
Copy link

Oh, that one looks interesting. Also looking for having Code Coverage for behat tests on phpunit. Using it with Jenkins. Do you know if there's a legacy code coverage for behat?

@cordoval
Copy link

whoever is automating travis behat scenarios out there https://gist.github.com/1298503 this is a nice way for doing such things as there is not yet a travis hook for behat, nicely done jakzal

@tvlooy
Copy link

tvlooy commented Dec 7, 2011

Seems I reached the point where I had too much features being executed with this. Random features broke and I couldn't reproduce it manually. I now solved this by splitting it up and putting just one feature in one of wrapper. You can add your feature like this:

$input = new ArrayInput(array(
'behat',
'-e' => 'test',
'--format' => 'progress',
'features' => 'path/to/your.feature'
));

@jakzal
Copy link
Author

jakzal commented Dec 7, 2011

Good idea @tvlooy! Other way of doing it might be using filters:

$input = new ArrayInput(array(
    'behat',
    '-e' => 'test',
    '--format' => 'progress',
    '--tags' => '@orm,@database'
));

@tvlooy
Copy link

tvlooy commented Dec 28, 2011

That works over here. Is xdebug installed and enabled?

@jakzal
Copy link
Author

jakzal commented Dec 28, 2011

Seems I managed to fix a problem with failing scenarios in big suites: http://www.zalas.eu/fixing-failing-behat-scenarios-in-large-suites

@khepin
Copy link

khepin commented Feb 1, 2012

Is the "KernelAwareTest" here the same as this gist: https://gist.github.com/1373056 ?

@jakzal
Copy link
Author

jakzal commented Feb 1, 2012

@khepin yes but here's the original: https://gist.github.com/1319290

@dantudor
Copy link

@elvisciotti
Copy link

I guess that is meant to be used when there are no http requests (mink steps) Behat/Behat#92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment