2 years ago

#35661

test-img

charliep

Can Behat be integrated with PHPUnit?

I have been setting up Behat in order to facilitate BDD as a testing framework for my company. The ask is to also incorporate it with PHPUnit, so as to derive the benefits of that platform, with the readability of the Gherkin syntax of the Behat scenarios.

My first attempt at integration with PHPUnit was to make php exec() calls out to the command line from the Behat Feature file, and base the results of each scenario step on the feedback from that PHPUnit test. This, however, feels cumbersome, and that there should be a way to more tightly integrate these tools, hopefully allowing Behat to call PHPUnit tests directly.

/**
 * @When <invoice_custcode>
 */
public function invoiceCustcode()
{
    $returnValue = "";
    $output = "";
    exec("phpunit BDDTest",$output,$returnValue);
    echo "returned with status ".$returnValue." and output=".print_r($output);

}

This far, the closest I have come is this project by Jonathan Shaw from 2019, but it doesn't seem to speak completely to my question.

https://medium.com/@jonathanjfshaw/write-better-tests-by-using-behat-with-phpunit-ddb08d449b73

testing

phpunit

integration

bdd

behat

0 Answers

Your Answer

Accepted video resources