0

I have problems with running PHPUnit tests using phpunit.xml file. I configured remote PHP interpreter like this:

Remote PHP interpreter configuration

This configuration allows me to debug PHP Web Application. I have the problem trying to debug PHPUnit scripts. I configured it like this:

PHPUnit configuration

With such configuration I can debug PHPUnit tests:

debugging PHPUnit test

The problem is that my PHPUnit file is not read and my environment variables are not used. As a result I got some errors like CSRF Token Validation exceptions in my tests.

How do I use my phpunit.xml file? I can see I can add default configuration file in PHPUnit configuration. I need to specify there my project directory, not the phpunit.xml itself.

I can see in PHPUnit's Command->handleArguments() function there are only two ways to load this file. I can either specify the directory where phpunit.xml is located or don't use --no-configuration option.

hendleArguments() function in Command class

Unfortunately when I specify the directory where my project is located as location of phpunit.xml, I loose the ability to debug my tests. What's interesting, I can still debug PHPUnit scripts (for example Command.php file).

I'd like not to add --no-configuration option in IntelliJ (PhpStorm), but it is automatically added when the field "Default configuration file" is not selected.

How do I load phpunit.xml file without loosing ability to debug my tests?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Artur Owczarek
  • 1,146
  • 1
  • 11
  • 22
  • Did you try to set it as a default configuration file in File | Settings | Languages & Frameworks | PHP | Test Frameworks > your remote PHPUnit configuration? – Vlad Luchansky Jul 18 '17 at 08:04

1 Answers1

1

The problem was the tests were run in isolation. When we specify either phpunit.xml file or project directory in PHPUnit configuration, the file is taken into consideration. What causes "detaching" debugger is running tests in isolation. To "fix" the problem we have to set attribute processIsolation to false:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
     backupStaticAttributes="false"
     bootstrap="bootstrap/autoload.php"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false">
...
</phpunit>
Artur Owczarek
  • 1,146
  • 1
  • 11
  • 22
  • Or configure PHP on that VM to have xdebug enabled. See as well a simlar question on that part: https://stackoverflow.com/q/45332246/367456 – hakre Jul 27 '17 at 00:29