Skip to content

Commit b843ecf

Browse files
Add tests for object comparison behavior and clarify uniqueValues() documentation (#354)
1 parent 1b99650 commit b843ecf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Assert.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ public static function email(mixed $value, string $message = ''): string
889889

890890
/**
891891
* Does non-strict comparisons on the items, so ['3', 3] will not pass the assertion.
892+
* Note: objects with identical properties are also considered equal.
892893
*
893894
* @throws InvalidArgumentException
894895
*/

tests/AssertTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static function getTests(): array
5353
$normalList = ['foo' => 'b', 3];
5454
unset($normalList['foo']);
5555

56+
$a = new ToStringClass('testString');
57+
$b = new ToStringClass('testString');
58+
$c = new ToStringClass('otherString');
59+
5660
return [
5761
['string', ['value'], true],
5862
['string', [''], true],
@@ -251,6 +255,9 @@ public static function getTests(): array
251255
['eq', [1, '1'], true],
252256
['eq', [1, true], true],
253257
['eq', [1, 0], false],
258+
['eq', [$a, $a], true],
259+
['eq', [$a, $b], true],
260+
['eq', [$a, $c], false],
254261
['notEq', [1, 0], true],
255262
['notEq', [1, 1], false],
256263
['notEq', [1, '1'], false],
@@ -259,10 +266,14 @@ public static function getTests(): array
259266
['same', [1, '1'], false],
260267
['same', [1, true], false],
261268
['same', [1, 0], false],
269+
['same', [$a, $b], false],
270+
['same', [$a, $a], true],
262271
['notSame', [1, 0], true],
263272
['notSame', [1, 1], false],
264273
['notSame', [1, '1'], true],
265274
['notSame', [1, true], true],
275+
['notSame', [$a, $b], true],
276+
['notSame', [$a, $a], false],
266277
['greaterThan', [1, 0], true],
267278
['greaterThan', [0, 0], false],
268279
['greaterThanEq', [2, 1], true],
@@ -283,8 +294,15 @@ public static function getTests(): array
283294
['notOneOf', [1, ['1', '2', '3']], true],
284295
['inArray', [1, [1, 2, 3]], true],
285296
['inArray', [1, ['1', '2', '3']], false],
297+
['inArray', [$a, [$a]], true],
298+
['inArray', [$a, [(string) $a]], false],
299+
['inArray', [$a, [$b]], false],
300+
['inArray', [$a, [$c]], false],
286301
['notInArray', [1, [1, 2, 3]], false],
287302
['notInArray', [1, ['1', '2', '3']], true],
303+
['notInArray', [$a, [$a]], false],
304+
['notInArray', [$a, [$b]], true],
305+
['notInArray', [$a, [$c]], true],
288306
['contains', ['abcd', 'ab'], true],
289307
['contains', ['abcd', 'bc'], true],
290308
['contains', ['abcd', 'cd'], true],
@@ -628,6 +646,9 @@ public static function getTests(): array
628646
['uniqueValues', [['qwerty', 'qwerty']], false],
629647
['uniqueValues', [['asdfg', 'qwerty']], true],
630648
['uniqueValues', [[123, '123']], false],
649+
['uniqueValues', [[$a, $a]], false],
650+
['uniqueValues', [[$a, $b]], false],
651+
['uniqueValues', [[$a, $c]], true],
631652
['isStatic', [static function () {}], true],
632653
['isStatic', [function () {}], false],
633654
['notStatic', [static function () {}], false],

0 commit comments

Comments
 (0)