Skip to content

Commit f95d174

Browse files
committedMar 17, 2025··
Create CallableAccess comparator test with invokable class
1 parent d86fb5b commit f95d174

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
 

‎tests/Comparator/CallableAccessTest.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/** @covers \Budgegeria\IntlSort\Comparator\CallableAccess */
1515
class CallableAccessTest extends TestCase
1616
{
17-
public function testDelegateToCollator(): void
17+
public function testCollatorWithFunction(): void
1818
{
1919
$func = static function (mixed $value): string {
2020
assert(is_array($value));
@@ -31,4 +31,25 @@ public function testDelegateToCollator(): void
3131

3232
self::assertSame(-1, $comparator->compare(['foo' => '1'], ['foo' => '2']));
3333
}
34+
35+
public function testCollatorWithClass(): void
36+
{
37+
$func = new class {
38+
public function __invoke(mixed $value): string
39+
{
40+
assert(is_array($value));
41+
42+
return (string) $value['foo'];
43+
}
44+
};
45+
$collator = self::createMock(Collator::class);
46+
$collator->expects(self::once())
47+
->method('compare')
48+
->with('1', '2')
49+
->willReturn(-1);
50+
51+
$comparator = new CallableAccess($collator, $func);
52+
53+
self::assertSame(-1, $comparator->compare(['foo' => '1'], ['foo' => '2']));
54+
}
3455
}

0 commit comments

Comments
 (0)
Please sign in to comment.