Bootstrap in tests/unit not loading #1223

alairock opened this Issue Jul 17, 2014 · 18 comments

_bootstrap.php in tests/unit does not load. Is this the intended behavior? Is there something I need to configure to enable it, or is this a bug?

Codeception 2.0.2


It was fixed in 2.0.3 that's to be released soon.

@samdark samdark closed this Jul 17, 2014

Awesome! Sorry for the duplicate ticket, and thanks for doing such a fine job :)


I just updated to 2.0.3 and checked out this issue, and it looks to be broken still.

Codeception Testing Framework member

Can you provide example in how you use it? Because we have internal tests that verify that bootstrap is loaded before each suite. @samdark wanted bootstrap to be loaded before suite modules, and this behavior was implemented in 2.0.3.

@DavertMik DavertMik reopened this Jul 22, 2014
@samdark samdark added this to the 2.0.3 milestone Jul 22, 2014
@samdark samdark self-assigned this Jul 22, 2014

After looking at it, it seems like it does load, but it's kind of weird.

I have a test class that looks kinda of like

   class RandomTest extends MasterUnitTest {


    require_once dirname(__FILE__) . '/MasterUnitTest.php';

And I get a failure to find class 'MasterUnitTest'.

It does not work when I use phpunit with a relative bootstrap path : phpunit --bootstrap _bootstrap.php RandomTest

But it does work when I use an absolute bootstrap path : phpunit --bootstrap ./_bootstrap.php RandomTest

Codeception Testing Framework member

Why do you use phpunit runner?
We discuss codeception here, and it loads bootstrap file automatically.


It's exercising the issue, so you can see what codeception is breaking on. Codeception is handling bootstrapped files as relative, whereas it needs the option of also being absolute. Because of this, codeception is not handling the require's correctly.


I created a quick little repo that is created with $ codecept bootstrap and shows the issue.

run codecept run unit from clone dir. (Failure)

$ phpunit --bootstrap tests/unit/_bootstrap.php tests/unit/RandomTest.php (Success)


I'm running Codeception 2.0.9 and I as well get an Error that a class, which I include via unit/_bootstrap.php, doesn't exist. The test works just fine if I include(unit/_bootstrap.php) into the global _bootstrap.php inside tests directory. It also runs fine if I run phpunit with bootstrap property of phpunit.xml pointing to unit/_bootstrap.php


I'm running into this error on Codeception 2.0.9.
I debugged it and found the problem in Codecept::runSuite()

public function runSuite($settings, $suite, $test = null) {
        $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
        $suiteManager->run($this->runner, $this->result, $this->options);
        return $this->result;

The TestFiles are loaded in SuiteManager::loadTests() while the bootstraping is done on the suite.before Event inside of the SuiteManager::run()
(see Codeception\Subscriber\Bootstrap)

As quick fix you can move the event dispatching into SuiteManager::loadTests().
But I dont understand the implications of this, so someone with knowledge should fix it.


I'm still having this issue on Codeception 2.0.14.


I'm having the same issue on Codeception 2.1.0-beta


Still the same issue on Codeception 2.1 stable.


Here is my (quick n dirty) workaround, please advise if you have better ideas:

// In /tests/_bootstrap.php
// PATH_TESTS is just "/tests/"
if (!empty($_SERVER['argv'][2]) && $_SERVER['argv'][2] == 'unit')
    require_once(PATH_TESTS . 'unit/_bootstrap.php');
@Naktibalda Naktibalda removed this from the 2.0.3 milestone Aug 20, 2015

version 2.1.2 same issue


RenaudParis wrote:

Here is my (quick n dirty) workaround, please advise if you have better ideas:

// In /tests/_bootstrap.php
// PATH_TESTS is just "/tests/"
if (!empty($_SERVER['argv'][2]) && $_SERVER['argv'][2] == 'unit')
    require_once(PATH_TESTS . 'unit/_bootstrap.php');

My advise:

if ($_SERVER['argv'][1] === 'run' and in_array('unit', $_SERVER['argv'])) {
    require_once(__DIR__ . '/unit/_bootstrap.php');

I just started a new project using Codeception 2.1.3 and there is no such issue.
Running unit suite always loads /unit/_bootstrap.php.


#0  require_once() called at [phar://ProjectDir/codecept.phar/src/Codeception/Subscriber/Bootstrap.php:34]
#1  Codeception\Subscriber\Bootstrap->loadBootstrap()
#2  call_user_func() called at [phar://ProjectDir/codecept.phar/vendor/symfony/event-dispatcher/EventDispatcher.php:164]
#3  Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() called at [phar://ProjectDir/codecept.phar/vendor/symfony/event-dispatcher/EventDispatcher.php:53]
#4  Symfony\Component\EventDispatcher\EventDispatcher->dispatch() called at [phar://ProjectDir/codecept.phar/src/Codeception/SuiteManager.php:152]
#5  Codeception\SuiteManager->run() called at [phar://ProjectDir/codecept.phar/src/Codeception/Codecept.php:203]
#6  Codeception\Codecept->runSuite() called at [phar://ProjectDir/codecept.phar/src/Codeception/Codecept.php:172]
#7  Codeception\Codecept->run() called at [phar://ProjectDir/codecept.phar/src/Codeception/Command/Run.php:262]
#8  Codeception\Command\Run->runSuites() called at [phar://ProjectDir/codecept.phar/src/Codeception/Command/Run.php:189]
#9  Codeception\Command\Run->execute() called at [phar://ProjectDir/codecept.phar/vendor/symfony/console/Command/Command.php:259]
#10 Symfony\Component\Console\Command\Command->run() called at [phar://ProjectDir/codecept.phar/vendor/symfony/console/Application.php:878]
#11 Symfony\Component\Console\Application->doRunCommand() called at [phar://ProjectDir/codecept.phar/vendor/symfony/console/Application.php:195]
#12 Symfony\Component\Console\Application->doRun() called at [phar://ProjectDir/codecept.phar/vendor/symfony/console/Application.php:126]
#13 Symfony\Component\Console\Application->run() called at [phar://ProjectDir/codecept.phar/codecept:34]
#14 require_once(phar://ProjectDir/codecept.phar/codecept) called at [ProjectDir/codecept.phar:7]

I'm having this problem too - the _bootstrap.php file in tests/unit is being loaded, but the one in tests/integration does not get loaded... it's as though it stops trying after finding the boostrap file of one test-suite, the rest don't get loaded? Very odd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment