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

ignoreIndirectDeprecations=true suppresses deprecations triggered in test code #6028

Closed
ostrolucky opened this issue Nov 14, 2024 · 2 comments
Assignees
Labels
feature/test-runner CLI test runner type/bug Something is broken

Comments

@ostrolucky
Copy link
Contributor

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.
@ostrolucky ostrolucky added the type/bug Something is broken label Nov 14, 2024
@sebastianbergmann
Copy link
Owner

This works as intended: test code is always considered to be first-party code.

@ostrolucky
Copy link
Contributor Author

This issue is about phpunit in fact, not doing that. I would expect phpunit report the deprecation, but it doesn't. Please reopen.

@sebastianbergmann sebastianbergmann added the feature/test-runner CLI test runner label Nov 16, 2024
@sebastianbergmann sebastianbergmann changed the title ignoreIndirectDeprecations=true in src suppresses direct test deprecations ignoreIndirectDeprecations=true suppresses deprecations triggered in test code Nov 25, 2024
@sebastianbergmann sebastianbergmann self-assigned this Nov 25, 2024
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/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants