Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Codeception with remote code coverage?

  • I have two repo on my machine
    1. API
    2. Codeception repo that tests API

In API repo I have added codeception+c3

"require-dev": {
    "codeception/codeception": "2.*",
    "codeception/c3": "2.*",

I've also included c3.php inside index.php, but when trying to test it with --coverage I have this error

[PHPUnit_Framework_Exception] file_get_contents(http://local.api.codeception.com/c3/report/clear): fai led to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

Is there ANY online example of remote codecoverage with Codeception?

like image 812
Ivan Z. Horvat Avatar asked Sep 22 '16 15:09

Ivan Z. Horvat


People also ask

What is Codeception selenium?

Codeception is very flexible framework that you can use to write your Selenium tests.

What is Codeception PHP?

Codeception is a multi-featured testing framework for PHP. It can handle unit, functional, and acceptance testing of web applications and it's powered by the already very popular PHPUnit testing framework.


2 Answers

Here's my configuration for remote codecoverage with Codeception (Project on GitHub).


Steps for running up remote codecoverage collection

1. Make sure that xdebug installed and enabled.

2. Configure codeception.

File codeception.yml (GitHub):

coverage:
  enabled: true
  c3_url: 'http://%SERVICE_HOST%/index-test.php/'
  include:
  - web/*
  - config/*
  - src/*

3. Enable coverage for the suits you need.

File acceptance.suite.yml (GitHub):

coverage:
  remote: true

In my example its enabled only for acceptance tests.

4. Include c3.php file in your application bootstrap.

Application bootstrap file index-test.php (GitHub):

// Start the remote code coverage collection.
require_once __DIR__.'/../c3.php';

// autoloader, application running and etc
// ...

5. Run coverage.

$ vendor/bin/codecept run --coverage --coverage-html

By default you can find your reports in tests/_output directory.


Possible issues

1. Output directory not writable (tests/_output).

$ chmod 777 tests/_output

2. Remote codecoverage not printed in console.

It should not be printed. From documentation:

coverage:
  remote: true

In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.

3. Some other error.

Try to enable debug. If debug enabled, you can get your report or clear it.

curl -o codecoverage.tar "http://localhost:8080/index-test.php/c3/report/html"

End

Sometimes it's not a trivial task. So I hope this will help!

like image 80
Anton Pelykh Avatar answered Oct 13 '22 19:10

Anton Pelykh


Ok, it was a configuration nightmare, but I've fixed it

Here is example

like image 36
Ivan Z. Horvat Avatar answered Oct 13 '22 20:10

Ivan Z. Horvat