skip to Main Content

I am working on transitioning a PHP application (more than 10 years old) to PHP 7.4, we are currently implementing a continuous integration on the PHP 7.4 branch of the application. We decided to use a version of PHPUnit that is supported by the PHP current stable release. So we upgraded the ci testing job of the PHP 7.4 branch to PHPUnit 9.3.

We made all necessary changes according to documentation, but we are blocked on one warning that we don’t know how to fix (granted the tests are executed and the report is published at the right place)

  Warning - The configuration file did not pass validation!

  The following problems have been detected:

  Line 38:
  - Element 'log': This element is not expected..

I am sharing our PHPUnit configuration below and the command we use to launch it, can anyone spot what is wrong with it?

phpunit -c phpunit.xml.dist


<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.3/phpunit.xsd"
    colors="true"
    bootstrap="tests/bootstrap.php"
>
    <testsuites>
        <testsuite name="Unit Tests">
            <directory>tests/</directory>
        </testsuite>
    </testsuites>
    <coverage>
        <include>
            <directory suffix=".php">api</directory>
        </include>
    </coverage>
    <logging>
        <log type="junit" target="build/unit_report.xml"/>
    </logging>
</phpunit>

2

Answers


  1. The <log> element has also changed in PHPUnit 9.3.

    You need to change

    <logging>
      <log type="junit" target="build/unit_report.xml"/>
    </logging>
    

    to

    <logging>
      <junit outputFile="build/unit_report.xml"/>
    </logging>
    

    That being said, I would highly recommend to use PHPUnit´s --migrate-configuration CLI option to automatically your configuration file to the new format.

    Login or Signup to reply.
  2. Changed in PHPUnit 9.5.x

    Try any from following

    <logging>
        <testdoxHtml outputFile="tests/coverage.html"/>
        <testdoxXml outputFile="tests/coverage.xml"/>
        <text outputFile="tests/coverage.txt"/>
    </logging>
    

    PHP Unit 9.5 Documentation – Logging

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search