Skip to content

Issue reporting deprecations when calls being made from 3rd party code #6434

@mpdude

Description

@mpdude

I am trying to collect deprecation notices while running the PHPUnit test suite in a Symfony application.

In general, I‘d like to ignoreIndirectDeprecations="true", since there are a lot of them between 3rd party packages I don‘t want to care about right now. But that currently also suppresses deprecations when my code is being called by framework code.

For example, there might be a Controller class that lives in my src and that triggers a deprecation notice. This controller, however, is not called directly by my test or other own source code, but during functional tests.

In the case of a controller, it‘s probably Symfony‘s HttpKernel invoking the controller method. In other cases (like Symfony Console commands), it may be other Symfony components calling my code.

From looking at \PHPUnit\Runner\ErrorHandler::trigger, it seems to me that since calls are not being made directly from my own (first party) code, this is always considered the indirect deprecation case which I‘d like to suppress.

I can try to work around this by adding the HttpKernel and other relevant parts from vendor as source files in the PHPUnit config. However, that does not exactly fit all cases since I don‘t want to see the cases where the Kernel is calling 3rd party code (which would be a direct deprecation if the Kernel is considered first party code).

[Edit: Moved second group of issues to #6435, since I think the cause and potential solutions are different.]

Additional information

PHPUnit 12.4.5, PHP 8.4.15

phpunit.xml.dist:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
    bootstrap="tests/bootstrap.php"
>
    <source ignoreSuppressionOfDeprecations="true" ignoreIndirectDeprecations="true">
        <deprecationTrigger>
            <function>trigger_deprecation</function>
        </deprecationTrigger>
        <include>
            <directory>src</directory>
        </include>
    </source>
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

test/bootstrap.php:

<?php

use Symfony\Component\ErrorHandler\DebugClassLoader;
use Symfony\Component\ErrorHandler\ErrorHandler;

require_once __DIR__.'/../vendor/autoload.php';

DebugClassLoader::enable();

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/issuesIssues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions