Skip to content

Commit

Permalink
chore: autofix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Feb 1, 2024
1 parent b8bfd5a commit 2cbba52
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tests/unit/IssuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ final class IssuesTest extends TestCase
use GenericCollectionProviders;
use IterableAssertions;

public function testCollectionSorting(): void
{
$input = Collection::fromIterable([
self::createValueObject(id: 1, weight: 2),
self::createValueObject(id: 160, weight: 1),
self::createValueObject(id: 1600, weight: 3),
self::createValueObject(id: 2, weight: 2),
self::createValueObject(id: 150, weight: 1),
self::createValueObject(id: 1500, weight: 3),
self::createValueObject(id: 3, weight: 2),
])
->sort(callback: static fn (object $a, object $b): int => $a->weight <=> $b->weight)
->map(static fn (object $item): int => $item->id);

self::assertEquals([160, 150, 1, 2, 3, 1600, 1500], $input->all());
}

public function testIssue264()
{
$subject = Collection::fromCallable(static function () {
Expand Down Expand Up @@ -57,17 +74,6 @@ public function __construct(
self::assertEquals([1, 2, 3], $input->all());
}

private static function createValueObject(int $id, int $weight): object
{
return new class($id, $weight) {
public function __construct(
public int $id,
public int $weight,
) {
}
};
}

public function testPhpSorting(): void
{
$input = [
Expand All @@ -87,20 +93,13 @@ public function testPhpSorting(): void
self::assertEquals([160, 150, 1, 2, 3, 1600, 1500], $collection->all());
}

public function testCollectionSorting(): void
private static function createValueObject(int $id, int $weight): object
{
$input = Collection::fromIterable([
self::createValueObject(id: 1, weight: 2),
self::createValueObject(id: 160, weight: 1),
self::createValueObject(id: 1600, weight: 3),
self::createValueObject(id: 2, weight: 2),
self::createValueObject(id: 150, weight: 1),
self::createValueObject(id: 1500, weight: 3),
self::createValueObject(id: 3, weight: 2),
])
->sort(callback: static fn (object $a, object $b): int => $a->weight <=> $b->weight)
->map(static fn (object $item): int => $item->id);

self::assertEquals([160, 150, 1, 2, 3, 1600, 1500], $input->all());
return new class($id, $weight) {
public function __construct(
public int $id,
public int $weight,
) {}
};
}
}

0 comments on commit 2cbba52

Please sign in to comment.