Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of PHPUnit XML Configuration file #4288

Closed
sebastianbergmann opened this issue Jun 11, 2020 · 4 comments
Closed

Migration of PHPUnit XML Configuration file #4288

sebastianbergmann opened this issue Jun 11, 2020 · 4 comments
Assignees
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jun 11, 2020

PHPUnit 9.3 introduces significant changes to PHPUnit's XML configuration file (phpunit.xml) for code coverage and logging:

PHPUnit 9.2

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
         cacheTokens="true"
         disableCodeCoverageIgnore="true"
         ignoreDeprecatedCodeUnitsFromCodeCoverage="true">
    <!-- ... -->

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true"
                   processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>

            <exclude>
                <directory suffix=".php">src/generated</directory>
                <file>src/autoload.php</file>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="html-coverage" lowUpperBound="50" highLowerBound="90"/>
        <log type="coverage-clover" target="clover.xml"/>
        <log type="coverage-crap4j" threshold="50" target="crap4j.xml"/>
        <log type="coverage-text" showUncoveredFiles="false" showOnlySummary="true" target="coverage.txt"/>
        <log type="junit" target="junit.xml"/>
        <log type="teamcity" target="teamcity.txt"/>
        <log type="testdox-html" target="testdox.html"/>
        <log type="testdox-text" target="testdox.txt"/>
        <log type="testdox-xml" target="testdox.xml"/>
        <log type="plain" target="logfile.txt"/>
    </logging>
</phpunit>

PHPUnit 9.3

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
    <!-- ... -->

    <coverage includeUncoveredFiles="true"
              processUncoveredFiles="true"
              ignoreDeprecatedCodeUnits="true"
              disableCodeCoverageIgnore="true">
        <include>
            <directory suffix=".php">src</directory>
        </include>

        <exclude>
            <directory suffix=".php">src/generated</directory>
            <file>src/autoload.php</file>
        </exclude>

        <report>
            <clover outputFile="clover.xml"/>
            <crap4j outputFile="crap4j.xml" threshold="50"/>
            <html outputDirectory="html-coverage" lowUpperBound="50" highLowerBound="90"/>
            <php outputFile="coverage.php"/>
            <text outputFile="coverage.txt" showUncoveredFiles="false" showOnlySummary="true"/>
            <xml outputDirectory="xml-coverage"/>
        </report>
    </coverage>

    <logging>
        <junit outputFile="junit.xml"/>
        <teamcity outputFile="teamcity.txt"/>
        <testdoxHtml outputFile="testdox.html"/>
        <testdoxText outputFile="testdox.txt"/>
        <testdoxXml outputFile="testdox.xml"/>
        <text outputFile="logfile.txt"/>
    </logging>
</phpunit>

It would be nice if there would be a way to automatically migrate a PHPUnit 9.2 XML configuration file to the new PHPUnit 9.3 syntax.

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner labels Jun 11, 2020
@sebastianbergmann sebastianbergmann self-assigned this Jun 11, 2020
@theseer
Copy link
Collaborator

theseer commented Jun 11, 2020

I'd be willing to provide such a migration in terms of code if you (or somebody else) takes care of integrating it into PHPUnit.

Side note: Before a migration can/should be attempted, the "current" xml configuration file needs to pass the old schema. For that reason, we'd need to bundle the old and the new xsd.

@sebastianbergmann
Copy link
Owner Author

Thank you for volunteering, Arne. I can take care of integrating this into PHPUnit. Please note that this needs to be ready in time for PHPUnit 9.3 which is due on August 7, 2020.

sebastianbergmann added a commit that referenced this issue Jul 18, 2020
@sebastianbergmann
Copy link
Owner Author

@theseer I have created a branch for this and 26d7270 is an initial commit that adds a (failing) test, the old XSD, as well as the skeleton for Migrator::migrateFrom92To93().

@theseer
Copy link
Collaborator

theseer commented Jul 18, 2020

Thanks!

Funny enough, I was already pondering if and how to detect what migration to run. Given that the XSD reference hasn't been around from the beginning and is technically optional, we do not really have a means to tell if a migration is needed and/or from what version. Correct?

I didn't actually check when and where things changed over time. I presume that there might be more changes coming for upcoming versions of PHPUnit. Are we caring about these?

Your skeleton code suggests that we "only" support migrating from 9.2 to 9.3, but doesn't yet tell on how to decide if any migration is needed. I take it that'll be your problem to solve? ;-)

I might be overthinking / over engineering this, but my initial design in my fork started with coming up with a flexible migration stack where based on the "incoming" version a list of migrations might be performed.

I also laid out various smaller migrations, so they can be run independently. Not sure yet, if that'll work since some things got moved around but i'll give it another go probably tomorrow evening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants