Skip to content

HRTime::duration() throws InvalidArgumentException #5652

@josep11

Description

@josep11
Q A
PHPUnit version 10.5.5
PHP version 8.3.0
Installation Method Composer

Summary

\PHPUnit\Event\Telemetry\HRTime::duration throws InvalidArgumentException

This line is the one that throws, but only sometimes.

public function duration(self $start): Duration
    {
        ...

        if ($seconds < 0) {
            throw new InvalidArgumentException('Start needs to be smaller.');
        }

       ...
    }

In my test it fails when invoking the createMock method.
Today: $logger = $this->createMock(LoggerInterface::class);
Yesterday: $calendar = $this->createMock(Calendar::class);

We have had that test running on our CI pipeline for over a year. PRs have been rised on a daily basis and it never failed till yesterday.

We upgraded to PHPUnit 10 one month ago. Same thing, it always worked.

Current behavior

We get one failed test case when running it on our CI provider. The step looks like this:

XDEBUG_MODE=off php -d memory_limit=-1 vendor/bin/phpunit --testsuite unit --colors=never

The same does not happen if we add another pipeline step with the phpunit "--filter"

XDEBUG_MODE=off php -d memory_limit=-1 vendor/bin/phpunit --testsuite unit --colors=never --filter="AttendeeController"

How to reproduce

It is extremely difficult to reproduce. I tried reproducing it locally and cannot succeed. Also, on the CI pipeline it's somehow inconsistent.

  • If I comment one of the data provider scenarios out, the error disappears. And then it appears on the immediately previous data provider scenario.
  • If I comment the immediately previous data provider scenario, it disappears. 🤯
  • If I comment all data providers out it disappears. But then randomly appears the next day on another test case.

Expected behavior

I would say that, if $seconds (which I am not sure how that can even happen 🤯) is less than 0, we should not care at all in the relevant test method. It should be caught and handled by PhpUnit as it's related to grabbing the total execution time.

In summary, it should not be leaked to the phpunit user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/eventsIssues related to PHPUnit's event systemtype/bugSomething is brokenversion/10Something affects PHPUnit 10version/11Something affects PHPUnit 11

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions