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

Migrate configuration from 10.5 to 11.4 #6023

Open
llaville opened this issue Nov 2, 2024 · 6 comments
Open

Migrate configuration from 10.5 to 11.4 #6023

llaville opened this issue Nov 2, 2024 · 6 comments
Labels
feature/configuration/xml type/enhancement A new idea that should be implemented

Comments

@llaville
Copy link

llaville commented Nov 2, 2024

Hello,

Working on my project BOX Manifest and wanted to migrate from PHPUnit 10 to 11, I've noticed that include uncovered files option was not included during migration process.

After installing PHPUnit 11.4.3, I've checks for regressions with following command :

vendor/bin/phpunit --display-phpunit-deprecations --no-coverage

And got this output :

[debug] Checking BOX_ALLOW_XDEBUG
[debug] The Xdebug extension is loaded (3.3.2) xdebug.mode=debug,develop
[debug] Process restarting (BOX_ALLOW_XDEBUG=internal|3.3.2|1|*|*)
[debug] Running: [/usr/local/bin/php, -n, -c, /tmp/nWkIvs, vendor/bin/phpunit, --display-phpunit-deprecations, --no-coverage]
[debug] Checking BOX_ALLOW_XDEBUG
[warning] Restarted (264 ms). The Xdebug extension is loaded (3.3.2) xdebug.mode=coverage
PHPUnit 11.4.3 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.25
Configuration: /shared/backups/bartlett/box-manifest/phpunit.xml.dist

................................................................. 65 / 91 ( 71%)
..........................                                        91 / 91 (100%)

Time: 00:03.492, Memory: 102.00 MB

There was 1 PHPUnit test runner deprecation:

1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!

OK, but there were issues!
Tests: 91, Assertions: 120, PHPUnit Deprecations: 1.
[debug] Restarted process exited 0

So I've run migration process with following command :

vendor/bin/phpunit --migrate-configuration

Anf got result :

PHPUnit 11.4.3 by Sebastian Bergmann and contributors.

Created backup:         /shared/backups/bartlett/box-manifest/phpunit.xml.dist.bak
Migrated configuration: /shared/backups/bartlett/box-manifest/phpunit.xml.dist

But when I compare versions, I was surprised on coverage section that missed previous attribute includeUncoveredFiles

Checks with command :

diff phpunit.xml.dist.bak phpunit.xml.dist --ignore-space-change

That prints :

2,18c2,3
< <phpunit
<     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<     xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
<     backupGlobals="false"
<     backupStaticProperties="false"
<     bootstrap="bootstrap.php"
<     colors="true"
<     stopOnError="false"
<     stopOnFailure="false"
<     stopOnIncomplete="false"
<     stopOnRisky="false"
<     stopOnSkipped="false"
<     beStrictAboutTestsThatDoNotTestAnything="false"
<     processIsolation="false"
<     cacheDirectory=".phpunit.cache"
< >
<     <coverage includeUncoveredFiles="true">
---
> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" backupGlobals="false" backupStaticProperties="false" bootstrap="bootstrap.php" colors="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnRisky="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" processIsolation="false" cacheDirectory=".phpunit.cache">
>   <coverage>

BTW, it will be cool if we can same identation after migration. Even if my PHP editor is able to easily re-indent code !

@llaville llaville added the type/enhancement A new idea that should be implemented label Nov 2, 2024
@llaville
Copy link
Author

llaville commented Nov 2, 2024

FYI: related to my previous report #6019, when there is a change in configuration (even if it's not expected, like includeUncoveredFiles attribute missing), the schema change is well detected.

@sebastianbergmann
Copy link
Owner

it will be cool if we can same identation after migration

While I agree that losing indentation is an inconvenience, it is annoying enough to invest time/effort in finding a solution to keep it.

@llaville
Copy link
Author

llaville commented Nov 2, 2024

I've noticed that documentation still identify the includeUncoveredFiles attribute, but not the schema 11.4 while schema 10.4 did it.

So, after re-introduced the attribute missing in my phpunit.xml.dist config file, I got another (wrong/not expected) warning

There was 1 PHPUnit test runner deprecation:

1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"! 

I think it's an issue, because includeUncoveredFiles is not identify by v11.4

@llaville
Copy link
Author

llaville commented Nov 2, 2024

Oops, I've in mind schema 10.5 and I present schema 10.4, but both identify correctly the missing attribute.

@see https://github.com/sebastianbergmann/phpunit/blob/main/schema/10.5.xsd#L65

@llaville
Copy link
Author

llaville commented Nov 2, 2024

While I agree that losing indentation is an inconvenience, it is annoying enough to invest time/effort in finding a solution to keep it.

Agree with you that it's time consuming. But I'll give you the solution, because I wanted to learn more about PHPUnit migration command.

With DOMDocument, when you set preserveWhiteSpace and formatOutput properties before loading file contents, it won't preserve indentation, and if you did it after it works.

Preserve indentation

<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist';

$configurationDocument = new \DOMDocument();
// either
//$configurationDocument->load($filename);
// or
$configurationDocument->loadXML(file_get_contents($filename));

$configurationDocument->preserveWhiteSpace = false;
$configurationDocument->formatOutput = true;

var_export($configurationDocument->saveXML());

DO NOT preserve indentation

<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist';

$configurationDocument = new \DOMDocument();

$configurationDocument->preserveWhiteSpace = false;
$configurationDocument->formatOutput = true;

// either
//$configurationDocument->load($filename);
// or
$configurationDocument->loadXML(file_get_contents($filename));

var_export($configurationDocument->saveXML());

In summary to fix PHPUnit, you have just to remove the line https://github.com/sebastianbergmann/phpunit/blob/11.4/src/Util/Xml/Loader.php#L67 because the good lines in right place are already defined at https://github.com/sebastianbergmann/phpunit/blob/11.4/src/TextUI/Configuration/Xml/Migration/Migrator.php#L47-L48

@nathan-de-pachtere
Copy link

nathan-de-pachtere commented Dec 4, 2024

@sebastianbergmann Not really sure if it's related to that thread but got warnings with many tags since migrating to 11.4

There was 1 PHPUnit test runner warning:

1) Test results may not be as expected because the XML configuration file did not pass validation:

  Line 14:
  - Element 'phpunit', attribute 'convertDeprecationsToExceptions': The attribute 'convertDeprecationsToExceptions' is not allowed.

  Line 31:
  - Element 'coverage', attribute 'includeUncoveredFiles': The attribute 'includeUncoveredFiles' is not allowed.

  Line 32:
  - Element 'include': This element is not expected.

  Line 37:
  - Element 'listeners': This element is not expected.

Here is my phpunit.xml.dist file

<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="tests/bootstrap.php"
         convertDeprecationsToExceptions="true"
         displayDetailsOnTestsThatTriggerDeprecations="true"
         displayDetailsOnTestsThatTriggerErrors="true"
         displayDetailsOnTestsThatTriggerNotices="true"
         displayDetailsOnTestsThatTriggerWarnings="true"
         displayDetailsOnPhpunitDeprecations="true"
>
    <php>
        <ini name="display_errors" value="1"/>
        <ini name="error_reporting" value="-1"/>
        <server name="APP_ENV" value="test" force="true"/>
        <server name="SHELL_VERBOSITY" value="-1"/>
        <server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
        <server name="SYMFONY_PHPUNIT_VERSION" value="11.5"/>
        <!-- ###+ snc/redis-bundle ### -->
        <!-- passwords that contain special characters (@, %, :, +) must be urlencoded -->
        <env name="REDIS_URL" value="redis://localhost"/>
        <server name="SYMFONY_DEPRECATIONS_HELPER"
                value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
        <!-- ###- snc/redis-bundle ### -->
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

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

    <listeners>
        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
    </listeners>

    <extensions>
        <bootstrap class="Zenstruck\Browser\Test\BrowserExtension"/>
        <bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
    </extensions>
</phpunit>

Here is the result of ./vendor/bin/phpunit --migrate-configuration

PHPUnit 11.4.4 by Sebastian Bergmann and contributors.

Migration of /app/phpunit.xml.dist failed:
The file does not validate against any known schema

Changing to xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" just make my IDE happy but doesn't change the warning.

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

No branches or pull requests

3 participants