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

XML configuration migration does not migrate whitelist/file elements #5405

Closed
anomiex opened this issue Jun 9, 2023 · 6 comments
Closed
Assignees
Labels
type/bug Something is broken version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10

Comments

@anomiex
Copy link

anomiex commented Jun 9, 2023

Q A
PHPUnit version 10.2.1, 9.6.8
PHP version 8.2.5, 8.0.28
Installation Method Composer

Summary

Migration fails if the <whitelist> uses <file>.

Current behavior

$ vendor/bin/phpunit --migrate-configuration
PHPUnit 10.2.1 by Sebastian Bergmann and contributors.

Created backup:         /tmp/test/phpunit.xml.dist.bak
Migration failed: whitelist element has unexpected children
$ vendor/bin/phpunit --migrate-configuration
PHPUnit 9.6.8 by Sebastian Bergmann and contributors.

Created backup:         /tmp/test/phpunit.xml.dist.bak
Migration failed: whitelist element has unexpected children

How to reproduce

  1. Create a phpunit.xml.dist like this, which is valid in older versions of PHPUnit.
    <phpunit>
    
        <testsuites>
            <testsuite name="main">
                <directory suffix=".php">tests/php</directory>
            </testsuite>
        </testsuites>
    
        <filter>
            <whitelist>
                <file>./*.php</file>
                <directory suffix=".php">src</directory>
            </whitelist>
        </filter>
    
    </phpunit>
  2. Run vendor/bin/phpunit --migrate-configuration

Expected behavior

Migration succeeds, producing this valid PHPUnit 10.2.1 configuration.

<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
  <coverage/>
  <testsuites>
    <testsuite name="main">
      <directory suffix=".php">tests/php</directory>
    </testsuite>
  </testsuites>
  <source>
    <include>
      <file>./*.php</file>
      <directory suffix=".php">src</directory>
    </include>
  </source>
</phpunit>

or this valid PHPUnit 9.6 configuration

<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
  <coverage>
    <include>
      <file>./*.php</file>
      <directory suffix=".php">src</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="main">
      <directory suffix=".php">tests/php</directory>
    </testsuite>
  </testsuites>
</phpunit>
@anomiex anomiex added type/bug Something is broken version/10 Something affects PHPUnit 10 version/9 Something affects PHPUnit 9 labels Jun 9, 2023
@sebastianbergmann
Copy link
Owner

The phpunit.xml.dist you show in step 1 is missing an XSD reference.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Jun 10, 2023
@anomiex
Copy link
Author

anomiex commented Jun 10, 2023

Which makes absolutely no difference to the early PHPUnit 9 versions or PHPUnit <9 versions that use <whitelist>. But add one in if you really want, the result is still the same.

@sebastianbergmann
Copy link
Owner

I need to know from which version you are trying to migrate.

@anomiex
Copy link
Author

anomiex commented Jun 10, 2023

No, you don't, because it doesn't matter.

But since you'll probably ignore this if I don't tell you a version despite the obvious bug, I've generated for you a fresh config file with PHPUnit 5.7.27, 6.5.14, 7.5.20, 8.5.33, and 9.2.6, all with one <file> added to trigger the bug.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         backupGlobals="false"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTestsThatDoNotTestAnything="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuite name="default">
        <directory suffix="Test.php">tests</directory>
    </testsuite>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>./*.php</file>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuite name="default">
        <directory suffix="Test.php">tests</directory>
    </testsuite>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>./*.php</file>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuites>
        <testsuite name="default">
            <directory suffix="Test.php">tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>./*.php</file>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         cacheResultFile=".phpunit.cache/test-results"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         convertDeprecationsToExceptions="true"
         verbose="true">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>./*.php</file>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>
<?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"
         bootstrap="vendor/autoload.php"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuites>
        <testsuite name="default">
            <directory suffix="Test.php">tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>./*.php</file>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

Happy now?

@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label Jun 11, 2023
@sebastianbergmann sebastianbergmann changed the title XML migration fails on <file> in <whitelist> XML configuration migration does not migrate whitelist/file elements Jun 11, 2023
@sebastianbergmann sebastianbergmann self-assigned this Jun 11, 2023
@sebastianbergmann
Copy link
Owner

No, you don't, because it doesn't matter.

Thank you for your patience and for providing me with the information I thought I needed.

The functionality controlled by --migrate-configuration was introduced in PHPUnit 9.3. It is only meant to support the migration of XML configuration files that are compatible with the phpunit.xsd of PHPUnit 8.5 (or newer). Therefore, PHPUnit 5.7.27, PHPUnit 6.5.14, PHPUnit 7.5.20 are out of scope here.

The exception is triggered by the RemoveEmptyFilter migration which assumes that the MoveWhitelistDirectoriesToCoverage migration, which is run before RemoveEmptyFilter, moved all <whitelist> elements from the old structure to the new structure. However, as the name already implies, MoveWhitelistDirectoriesToCoverage only moves whitelist/directory elements, thus leaving behind whitelist/file elements.

This will be addressed shortly.

@liorchamla
Copy link

@anomiex broo .. hard way to ask for help :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

3 participants