imbo / behat-api-extension

API extension for Behat, used to ease testing of JSON-based APIs
MIT License
107 stars 42 forks source link

Code coverage via Symphony client #72

Closed vitalyiegorov closed 6 years ago

vitalyiegorov commented 6 years ago

@christeredvartsen We have faced a situation where we would like to get code coverage by running web api tests. I believe that this is possible if we can change Guzzle client to Symfony Client. Do you know any ClientInterface implementation for this? Our we can make our own? What do you think?

christeredvartsen commented 6 years ago

Are you running tests against the PHP httpd, or some other web server? I'm collecting code coverage through the internal PHP httpd through a custom router and some HTTP headers set in the Guzzle client. I can share the setup if you want?

vitalyiegorov commented 6 years ago

We have apache setup, can you please share your config?

christeredvartsen commented 6 years ago

Created a gist with the relevant parts here:

https://gist.github.com/christeredvartsen/de3123c0c5cba1519ab57cd3e3e5a665

The router.php file needs to handled somewhat different since you use Apache, but you could probably just include it in your bootstrap file when in debug/dev mode or something similar.

The gist also includes a configuration file that enables code coverage, so when I want to collect coverage I can just use that file:

./vendor/bin/behat -c behat-coverage.yml

With this setup you won't need to change the Behat API extension at all.

christeredvartsen commented 6 years ago

@vitalyiegorov Did you get code coverage up and running?

christeredvartsen commented 6 years ago

:zzz: