Linking an external resource on PHPUnit xml config file

39 views Asked by At

I would like to know if it is possible to configure my PHPUnit xml to link/load a filter element from another xml file.

phpunit.xml

...
...
<logging>
    <log type="coverage-html" target="../tmp/coverage" lowUpperBound="35" highLowerBound="80"/>
</logging>


<filter xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">
    <whitelist xlink:type="locator" xlink:href="whitelist-foo.xml" />
</filter>

whitelist-foo.xml

<whitelist addUncoveredFilesFromWhitelist="false" processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../Providers</directory>
<exclude>
    <file>../Providers/AbstractService.php</file>
    <file>../Providers/GlobalFunctionsWrapper.php</file>
</exclude>

The idea is to allow other developers to just change the name of the whitelist href to point to another xml file, according to the modules they want to test. For example, if I want the whitelist-bar.xml, I would just edit the phpunit.xml to point to this file:

<filter xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">
    <whitelist xlink:type="locator" xlink:href="whitelist-bar.xml" />
</filter>

Results so far

When I try to run my tests, I get the following:

Runtime:       PHP 7.2.34 with Xdebug 3.1.3
Configuration: /var/www/html/my-project/tests/phpunit-coverage.xml
Extension:     /var/www/html/my-project/tests/tools/dbunit.phar is not compatible with this version of PHPUnit

  Warning - The configuration file did not pass validation!
  The following problems have been detected:

  Line 13:
  - Element 'filter', attribute '{http://www.w3.org/1999/xlink}type': The attribute '{http://www.w3.org/1999/xlink}type' is not allowed.

  Line 14:
  - Element 'whitelist', attribute '{http://www.w3.org/1999/xlink}type': The attribute '{http://www.w3.org/1999/xlink}type' is not allowed.
  - Element 'whitelist', attribute '{http://www.w3.org/1999/xlink}href': The attribute '{http://www.w3.org/1999/xlink}href' is not allowed.

  Test results may not be as expected.

Error:         Incorrect whitelist config, no code coverage will be generated.

I would like to know if it's even possible to do this. Otherwise, I'm thinking of just having several phpunit.xml files (i.e phpunit-foo.xml, phpunit-bar.xml), even if I end up having repeated configs in them.

0

There are 0 answers