Skip to content

Commit

Permalink
Add test for sorting of collection methods
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Sep 10, 2024
1 parent 2186aed commit b93c6f9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Collection/AbstractCollectionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,39 @@ public function testValues(): void
self::assertSame([5, 4, 7], $collection->values()->all(true));
}

public function testCollectionHasMethodsArrangedInParticularOrder(): void
{
$reflection = new \ReflectionClass($this->collection());
$publicMethods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
$sortedPublicMethods = $publicMethods;
usort(
$sortedPublicMethods,
static function (\ReflectionMethod $a, \ReflectionMethod $b): int {
if ($a->isConstructor()) {
return -1;
}

if ($b->isConstructor()) {
return 1;
}

if ($a->isStatic() && ! $b->isStatic()) {
return -1;
}

if (! $a->isStatic() && $b->isStatic()) {
return 1;
}

return strcmp($a->getName(), $b->getName());
},
);
$publicMethods = array_map(static fn(\ReflectionMethod $rm): string => $rm->getName(), $publicMethods);
$sortedPublicMethods = array_map(static fn(\ReflectionMethod $rm): string => $rm->getName(), $sortedPublicMethods);

self::assertSame($sortedPublicMethods, $publicMethods);
}

/**
* @template TKey
* @template T
Expand Down

0 comments on commit b93c6f9

Please sign in to comment.