Skip to content

assertContainsEquals() does not work with DateInterval objects #5922

Open
@sebastianstucke87

Description

Q A
PHPUnit version 11.3.0
PHP version 8.3.10
Installation Method Composer

Summary

assertContainsEquals does not work with \DateInterval

Current behavior

test_2 failes with ErrorException: Warning: Cannot compare DateInterval objects

How to reproduce

public function test_1()
{
    $a = \DateInterval::createFromDateString('1 DAY');
    $b = \DateInterval::createFromDateString('1 DAY');

    // ok
    $this->assertEquals($a, $b);
    $this->assertEqualsCanonicalizing($a, $b);
}

public function test_2()
{
    $a = \DateInterval::createFromDateString('1 DAY');
    $b = \DateInterval::createFromDateString('1 DAY');

    // ErrorException: Warning: Cannot compare DateInterval objects
    $this->assertContainsEquals($a, [$b]);
}

Expected behavior

test_2 passes without warnings

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature/assertionIssues related to assertions and expectationstype/bugSomething is brokenversion/11Something affects PHPUnit 11

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions