Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Codeception tests with Xdebug

I wrote some API tests with Codeception's ApiGuy. Now I want to set breakpoints in my PhpStorm 7 for tests debugging, but have no idea how to start debug session after $ vendor/bin/codecept run. I know about --debug option, but it's not exactly what I want.

Do you have any idea? Thanks in advance!

like image 495
Vitaly Chirkov Avatar asked Sep 04 '13 06:09

Vitaly Chirkov


3 Answers

I ran into the same problem. Seems that Codeception only comes with a command line tool, which cannot be debugged. I finally ended up writing my own PHP runner, which is basically a lite copy of the codeception command executable.

Actually all you would have to do in Linux is to remove the shebang from the codeception tool to run it as a PHP script. But since commands other then codeception run are much less likely to be a subject of debugging, I've prepared a separate PHP script. It contains only the run option:

<?php
/**
 * Codeception PHP script runner
 */

require_once dirname(__FILE__).'/../vendor/codeception/codeception/autoload.php';

use Symfony\Component\Console\Application;

$app = new Application('Codeception', Codeception\Codecept::VERSION);
$app->add(new Codeception\Command\Run('run'));

$app->run();

After you get this done you can set up your debugging script like any other in PHPStorm. So go to the Select Run/Debug Configuration > Edit Configurations...:

Edit Configurations...

Now Add New Configuration (Alt + Insert) > PHP Script. Then name the run configuration and select the file you created above. Remember to add the run argument:

enter image description here

And that's it. Now you can run your tests from within the IDE and debug them as ordinary scripts.

like image 168
Maciej Sz Avatar answered Oct 13 '22 11:10

Maciej Sz


I use the codecept.phar file and I find this one does work. just type this command in the console and then run the codeception tests:

export XDEBUG_CONFIG="idekey=session_name remote_host=localhost profiler_enable=1"
like image 38
user3391306 Avatar answered Oct 13 '22 10:10

user3391306


I would suggest to use

php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=On -dxdebug.idekey=YOUR_KEY -dxdebug.remote_host=YOUR_IP ../vendor/bin/codecept run
like image 26
Dezigo Avatar answered Oct 13 '22 10:10

Dezigo