sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.7k stars 2.2k forks source link

False positive phpunit deprecation when using a local XSD #5971

Closed benfreke closed 1 month ago

benfreke commented 1 month ago
Q A
PHPUnit version 11.3.6
PHP version 8.3.8
Installation Method Composer

Summary

Running phpunit with the option --display-phpunit-deprecations shows the warning 1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!

This is because I have updated the schema to be the path to the XSD that is downloaded with phpunit. The line in my phpunit.xml file is

xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"

Phpunit says that this is invalid and I should instead be pointing at a link on the internet to the 11.3 version of the file. Phpstorm complains if I haven't downloaded this locally, which is why I changed it to the local version so it would always be up to date. Those files should be exactly the same and therefore I think this deprecation is incorrect?

When I run the tool, that value is the only change made.

Current behavior

Phpunit complains that the local XSD for the phpunit.xml is deprecated.

How to reproduce

  1. Install phpunit into any project via composer
  2. Update the URL for the xsi:noNamespaceSchemaLocation to be vendor/phpunit/phpunit/phpunit.xsd
  3. Run phpunit with the option --display-phpunit-deprecations
  4. Note the error saying to run the migration configuration.

Expected behavior

No deprecation warnings during a standard run of phpunit, and nothing displayed with the option --display-phpunit-deprecations

sebastianbergmann commented 1 month ago

I cannot reproduce this.

composer.json

{
    "require-dev": {
        "phpunit/phpunit": "^11.3"
    }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         cacheDirectory=".phpunit.cache"
         executionOrder="depends,defects"
         shortenArraysForExportThreshold="10"
         requireCoverageMetadata="true"
         beStrictAboutCoverageMetadata="true"
         beStrictAboutOutputDuringTests="true"
         displayDetailsOnPhpunitDeprecations="true"
         failOnPhpunitDeprecation="true"
         failOnRisky="true"
         failOnWarning="true">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
        <include>
            <directory>src</directory>
        </include>
    </source>
</phpunit>

tests/Issue5971Test.php

<?php declare(strict_types=1);
namespace PHPUnit\TestFixture\Issue5971;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
final class Issue5971Test extends TestCase
{
    public function testOne(): void
    {
        $this->assertTrue(true);
    }
}
❯ ./vendor/bin/phpunit --display-phpunit-deprecations
PHPUnit 11.3.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.12
Configuration: /tmp/5971/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 00:00.004, Memory: 8.00 MB

OK (1 test, 1 assertion)
sebastianbergmann commented 1 month ago

No feedback, closing.