Skip to content

Commit 8e3b7c1

Browse files
Closes #5811
1 parent 53eebaa commit 8e3b7c1

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

ChangeLog-11.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes of the PHPUnit 11.2 release series are documented in this fi
88

99
* [#5799](https://github.com/sebastianbergmann/phpunit/issues/5799): `#[CoversTrait]` and `#[UsesTrait]` attributes
1010
* [#5804](https://github.com/sebastianbergmann/phpunit/pull/5804): Support doubling `readonly` classes
11+
* [#5811](https://github.com/sebastianbergmann/phpunit/issues/5811): `assertObjectNotEquals()`
1112

1213
### Deprecated
1314

src/Framework/Assert.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,20 @@ final public static function assertObjectEquals(object $expected, object $actual
468468
);
469469
}
470470

471+
/**
472+
* @throws ExpectationFailedException
473+
*/
474+
final public static function assertObjectNotEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
475+
{
476+
static::assertThat(
477+
$actual,
478+
static::logicalNot(
479+
static::objectEquals($expected, $method),
480+
),
481+
$message,
482+
);
483+
}
484+
471485
/**
472486
* Asserts that a variable is empty.
473487
*

src/Framework/Assert/Functions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,20 @@ function assertObjectEquals(object $expected, object $actual, string $method = '
484484
}
485485
}
486486

487+
if (!function_exists('PHPUnit\Framework\assertObjectNotEquals')) {
488+
/**
489+
* @throws ExpectationFailedException
490+
*
491+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
492+
*
493+
* @see Assert::assertObjectNotEquals
494+
*/
495+
function assertObjectNotEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
496+
{
497+
Assert::assertObjectNotEquals(...func_get_args());
498+
}
499+
}
500+
487501
if (!function_exists('PHPUnit\Framework\assertEmpty')) {
488502
/**
489503
* Asserts that a variable is empty.

tests/unit/Framework/AssertTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,19 @@ public function testTwoObjectsCanBeAssertedToBeEqualUsingComparisonMethod(): voi
22822282
$this->fail();
22832283
}
22842284

2285+
public function testTwoObjectsCanBeAssertedToNotBeEqualUsingComparisonMethod(): void
2286+
{
2287+
$this->assertObjectNotEquals(new ValueObject(1), new ValueObject(2));
2288+
2289+
try {
2290+
$this->assertObjectNotEquals(new ValueObject(1), new ValueObject(1));
2291+
} catch (AssertionFailedError) {
2292+
return;
2293+
}
2294+
2295+
$this->fail();
2296+
}
2297+
22852298
public function testObjectHasPropertyCanBeAsserted(): void
22862299
{
22872300
$objectWithProperty = new stdClass;

0 commit comments

Comments
 (0)