17
  • 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?

Ivan Z. Horvat
  • 385
  • 1
  • 4
  • 14
  • 1
    - Ok, I wasn't lazy so I did a small repo with API and codeception tests for API - Really don't know how to setup YML the right way https://github.com/Horki/remotecoverage – Ivan Z. Horvat Sep 29 '16 at 15:49
  • 1
    have you tried to display the error which happens in c3? there is a constant you can set with "define('C3_CODECOVERAGE_ERROR_LOG_FILE', '/path/to/c3_error.log');" before including c3.php (@see https://github.com/Codeception/c3#setup) Within the file you should see the error why there is a 500 result. – NiMeDia Oct 05 '16 at 08:47
  • A similar error and issue that might help: https://github.com/Codeception/Codeception/issues/655 – desc Oct 06 '16 at 00:42

2 Answers2

2

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!

Anton Pelykh
  • 2,274
  • 1
  • 18
  • 21
1

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

Here is example

Ivan Z. Horvat
  • 385
  • 1
  • 4
  • 14