2

I'm trying to run some commands on a Jenkins server to have PHPUnit execute the tests and report the results.

When I do require_once 'craft/app/bootstrap.php'; It is giving an error saying: PHP Notice: Undefined index: SERVER_NAME in craft/app/bootstrap.php on line 105

I read that you cannot use bootstrap.php in the craft/app folder because you're essentially trying to bootstrap a webapp (and this server isn't a webserver). It was suggested that I use craft/etc/console/yiic.php as my bootstrap file for PHPUnit. However, this is throwing errors about CDbConnection and is unable to connect.

Is there any way to bootstrap Craft from a command line to run PHPUnit? I'm unable to get it working without an apache server.

2

I read that you cannot use bootstrap.php in the craft/app folder because you're essentially trying to bootstrap a webapp (and this server isn't a webserver).

Not sure where you read that, but that doesn't sound right.

I'm assuming you've got a multi-environment config setup? If so, then manually set the CRAFT_ENVIRONMENT PHP constant before you load the Craft bootstrap.php file to the environment you want Craft to load in the config files.

That will get rid of the Undefined index: SERVER_NAME error you're getting as well as should fixed your database connection issue.

3
  • So what about at the top of my phpunit bootstrap file before I call craft's bootstrap file? Just literally define a PHP constant? Like define("CRAFT_ENVIRONMENT", "dev") ??
    – Exziled
    May 17 '16 at 13:29
  • Sounds about right!
    – Brad Bell
    May 17 '16 at 17:08
  • That did resolve the error, now onto the next error in a long list of them to get phpunit working on jenkins -.- thanks!
    – Exziled
    May 17 '16 at 17:29
1

Maybe an edge case, but if you're using the Kint logging/dumping extension for Craft in your console command, be careful. I got the undefined index SERVER_NAME error trying to to save an entry and output success/fail:

d(craft()->entries->saveEntry($entryModel)); --> SERVER_NAME index error

This fixed it:

$save_result = craft()->entries->SaveEntry($entryModel);
d($save_result);

Hope that saved someone a few minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.