Skip to content

PHPUnitHandler::isVerbose() assumes $_SERVER['argv'] exists in non-CLI contexts #33

@jaugustin

Description

@jaugustin

Hello,

Following Symfony 7.4 latest upgrade (containing security fixes) I got trouble with our test suite.

AI suggesting root cause from Assert lib.

PHPUnitHandler::isVerbose() directly reads $_SERVER['argv'].
In HTTP/non-CLI contexts, $_SERVER['argv'] can be missing. When an assertion fails, the failure formatting triggers an Undefined array key "argv" warning/type error and masks the original assertion failure.

Reproducer:

require 'vendor/autoload.php';
unset($_SERVER['argv']);
Zenstruck\Assert::try(
    fn () => throw new RuntimeException('original failure'),
    'Assertion wrapper failure',
);

Actual result:

Undefined array key "argv" from PHPUnitHandler::isVerbose().

Expected result:

The original assertion failure should be reported.

Potential fix:

public static function isVerbose(): bool
{
    $argv = $_SERVER['argv'] ?? [];
    return \in_array('--verbose', $argv, true) || \in_array('-v', $argv, true);
}

This appeared through zenstruck/messenger-test because TestTransport calls Assert::try() when test_serialization is enabled, but the crashing code is in zenstruck/assert.

I can make a MR if you think this is a valid bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions