How to Integrate Codeception’s c3.php into Laravel4 – Step by Step

(Before we start here, if you’d like to see this, and other technical posts like this, done on video in the future, please say so in the comments below. Thanks!)

After banging my head against a wall trying to integrate Codeception’s c3.php into Laravel for code coverage, I realized it wasn’t as hard as I had thought.  Regardless, here’s my post on how I did it.


You’ll need xdebug installed with remote_enable option turned on.

Here we go

I was doing functional tests, so here’s an example functional.suite.yml with the coverage element added. You’ll want to add that to any/all your test .yml files.

# Codeception Test Suite Configuration

# suite for functional (integration) tests.
# emulate web requests and make application process them.
# Include one of framework modules (Symfony2, Yii2, Laravel4) to use it.

class_name: FunctionalTester
    enabled: [Filesystem, FunctionalHelper, Laravel4, Db]
            cleanup: true
        remote: true

And then you add the coverage element with attributes as you need to configure into codeception.yml, which should also be in the root of your project.

Here’s mine:

actor: Tester
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
    enabled: true
    remote: true
        - app/*
        - app/config/*
        - app/database/*
        - app/lang/*
        - app/storage/*
        - app/tests/*
            dsn: 'mysql:host=localhost;dbname=eg_testing'
            user: 'homestead'
            password: 'secret'
            dump: tests/_data/dump.sql

Put the c3.php file in the root of your project (not the app directory). Then, make sure you require it in your /public/index.php like this:

 * Adding c3.php for code coverage during codeception tests
 * ref:

require __DIR__.'/../c3.php';

If you ran a test right now, it’s supposed to create a directory called c3tmp, but sometimes it doesn’t do it. So, I created my own c3tmp directory inside the root of the project and then did chmod 0777 c3tmp to make 100% certain there weren’t permissions problems writing to it.

Run a test using the --coverage flag. I ran codecept run functional --coverage.

Voila. You should see something like this screenshot.

Codeception c3 code coverage

If you want a pretty HTML report… because I like pretty HTML things… You can instead run codecept run functional --coverage-html.

Then go to your /tests/_output/coverage folder and open index.html in a browser.

Ta da!

Codeception HTML code coverage in Laravel

Time to stop writing this post and start writing more tests for better coverage.


Nate Ritter lives in the Pacific Northwest (U.S.), popularized the #hashtag and creates web applications for a living. He also does miles and point hacking to enable cheap travel for his family. More here →

3 Comments on "How to Integrate Codeception’s c3.php into Laravel4 – Step by Step"

  1. Mike says:

    Thanks for the short tutorial, exactly what I needed (Forgot to update the yml files with `remote: true`)

  2. I do not what I am doing wrong but I get 0 on everything :(

    Any idea why?

More in Development, Techie
Why I Removed Social Media Widgets

I've done a small underground overhaul on this blog by switching hosts to Media Temple because it's been faster and...