Skip to content

ignoreIndirectDeprecations=true suppresses deprecations triggered in test code #6028

@ostrolucky

Description

@ostrolucky
Q A
PHPUnit version 11.4.3
PHP version 8.3.3
Installation Method Composer

Summary

ignoreIndirectDeprecations="true" in source section apparently also applies to deprecations triggered directly in test cases. I was surprised to find out, because this is a recommended setting, but I find it useful to know about direct deprecations in test files.

Current behavior

.                                                                   1 / 1 (100%)

Time: 00:00.016, Memory: 8.00 MB

OK (1 test, 1 assertion)

How to reproduce

composer.json

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

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit failOnDeprecation="true"
>
    <testsuites>
        <testsuite name="Project Test Suite">
            <file>IssueXTest.php</file>
        </testsuite>
    </testsuites>
    <source ignoreIndirectDeprecations="true">
        <include>
            <directory>src</directory>
        </include>
    </source>
</phpunit>

IssueXTest.php

<?php

class IssueXTest extends \PHPUnit\Framework\TestCase
{
    public function test()
    {
        $this->foo = 'bar';
        self::assertSame(true, true);
    }
}

Expected behavior

D                                                                   1 / 1 (100%)

Time: 00:00.017, Memory: 8.00 MB

1 test triggered 1 PHP deprecation:

1) /Users/gostrolucky/Documents/phpunit-repro/IssueXTest.php:7
Creation of dynamic property IssueXTest::$foo is deprecated

Triggered by:

* IssueXTest::test
  /Users/gostrolucky/Documents/phpunit-repro/IssueXTest.php:5

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions