donatj / mock-webserver

Simple mock web server in PHP for unit testing.
MIT License
131 stars 21 forks source link

Adds env variable when starting server process for avoiding conflicts when debugging #21

Closed javierseixas closed 4 years ago

javierseixas commented 5 years ago

See https://github.com/donatj/mock-webserver/issues/20 for reading about the problem.

The solution proposed is to start server's php process changing the php variable xdebug.idekey.

Looking forward your feedback.

donatj commented 5 years ago

Correct me if I'm wrong here, but couldn't you just call

putenv("XDEBUG_CONFIG=idekey=mock");

in your code before starting the server and the sub-processes would automatically inherit it?

javierseixas commented 5 years ago

I just tested, and I'm afraid it doesn't.

I put it just before server->start(), but it gets stuck. Apparently, the parent process of the php server process is not the current php process. Look:

root@911e31c3ea33:/var/www# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  17960  2764 ?        Ss   15:40   0:00 bash -c while true; do
root        18  0.0  0.0  18144  3188 pts/1    Ss   15:41   0:00 bash
root       123  0.0  0.2 294924 33728 pts/1    S+   16:03   0:00 php test.php
root       124  0.1  0.0  18140  3104 pts/0    Ss   16:03   0:00 bash
root       137  0.0  0.1 421640 30348 pts/1    S+   16:03   0:00 php -S 127.0.0.1:81 /v
root       145  0.0  0.0   4200   652 ?        S    16:05   0:00 sleep 60
root       150  0.0  0.0  36640  2808 pts/0    R+   16:05   0:00 ps aux

php.test has pid 123. php -S has pid 137.

When I get php -S parent pid i get:

root@911e31c3ea33:/var/www# cat /proc/137/status | grep PPid
PPid:   1

Don't know why is created from pid 1 instead of 123. I'm in a docker container of the image fsateler/php:stretch. I don't know if this kind of things are configurable.

donatj commented 4 years ago

I think I'd rather see a more general solution where the user could define environmental variables.

javierseixas commented 4 years ago

Any example?

donatj commented 4 years ago

Could you give me a simple example showing how to trigger the stall?

I'm not able to currently reproduce.

donatj commented 4 years ago

Closing in lieu of an example of how to trigger the stall.