moodlehq / moodle-docker

A docker environment for moodle developers
GNU General Public License v3.0
373 stars 244 forks source link

breakpoints for phpUnit Tests when running in the container #240

Closed georgmaisser closed 1 year ago

georgmaisser commented 1 year ago

Hi, is there any chance to use breakpoints when running the phpUnit (or Behat) tests in the container? This would help so much! I couldn't find out a good way of debugging those tests with the docker setup.

scara commented 1 year ago

Hi @georgmaisser, XDebug? Ref: README.

HTH, Matteo

georgmaisser commented 1 year ago

Hi @georgmaisser, XDebug? Ref: README.

HTH, Matteo

Ok, this is obvious, but while I can debug via Chrome, I can't do it when triggering behat & unit tests. There must be something else to add to listen to these tests... thank you!

scara commented 1 year ago

Hi @georgmaisser,

There must be something else to add to listen to these tests... thank you!

Let me understand:

  1. you develop locally on your PC and the code is hosted on your PC but the web server
  2. you use the Moodle Docker Toolbox to run your local code and activate the XDebug engine via your local Browser
  3. you use the Moodle Docker Toolbox to run tests against your local code to avoid setting up the ancillary services locally on your machine
  4. you want to debug those PHPUnit tests running on the Moodle Docker Toolbox
  5. you want to debug those Behat tests running on the Moodle Docker Toolbox

Behat runs give you the possibility to collect the screenshots when failing and you could replicate the scenario locally by exposing the web server as you're probably already doing i.e. AFAIK you can't debug remotely a Behat test. https://moodledev.io/general/development/tools/behat/running#the-tests-are-failing-and-the-error-message-is-completely-useless could be of some help. In the past someone already try to post a request in the Community unfortunately w/o any reply.

PHPUnit should be executed starting from your IDE to allow XDebug to be activated: https://docs.moodle.org/dev/Setting_up_PhpStorm#Debugging_with_Xdebug_with_docker_containers could be of some help together with the previous link from the README.

Disclaimer: I do not use any remote debug option while running the tests.

HTH, Matteo

georgmaisser commented 1 year ago

Thank you so much for your detailed explanations!

Just for context: I run the docker container locally and use VSCode to develop, exactly like everything is explained in the readme.

The important part for me are the phpUnit tests. Thanks to your explanation I did the following. I added this to the base.yml:

XDEBUG_CONFIG: idekey=VSCODE remote_enable=1 remote_mode=req remote_port=9003 remote_host=host.docker.internal remote_connect_back=0 PHP_IDE_CONFIG: serverName=moodle-local

After reinstalling xdebug as usual within the container, the Breakpoints actually worked! That was the missing piece for me!

As for the behat: You are right of course that one can replicate, but sometimes there are situations where it would be nice to actually see which value is used in the behat test. With "I wait for "100" seconds and Developer Tools in Chrome within VNC, a lot is possible, but I once had a modal failing only within the behat environment and it was very hard to debug.

But your answer helped a lot to solve most of my problem, so thank you very much!

stronk7 commented 1 year ago

Thanks @scara and @georgmaisser ! If there is anything that can be added to the instructions to make it easier, feel free to suggest it in some PR!

Ciao :-)