Skip to content

Commit

Permalink
Merge pull request #217 from Jeroen-G/fix-sort-tests-on-master
Browse files Browse the repository at this point in the history
Fix sort related tests
  • Loading branch information
Jeroen-G committed Sep 22, 2023
2 parents 13f4656 + 38f0c75 commit e39853f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Infrastructure/Scout/ScoutSearchCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ScoutSearchCommandBuilder implements SearchCommandInterface

private ?string $minimumShouldMatch = null;

/** @var SyntaxInterface[] */
/** @var Sort[] */
private array $sort = [];

private array $aggregations = [];
Expand Down Expand Up @@ -208,7 +208,7 @@ public function setLimit(?int $limit): void

public function setSort(array $sort): void
{
Assert::allIsInstanceOf($sort, SyntaxInterface::class);
Assert::allIsInstanceOf($sort, Sort::class);
$this->sort = $sort;
}

Expand Down Expand Up @@ -305,11 +305,11 @@ public function getOffset(): ?int
return $this->offset;
}

/** @return SyntaxInterface[] */
/** @return Sort[] */
private static function getSorts(Builder $builder): array
{
return array_map(static function($order) {
return $order instanceof SyntaxInterface ? $order : new Sort($order['column'], $order['direction']);
return $order instanceof Sort ? $order : new Sort($order['column'], $order['direction']);
}, $builder->orders);
}
}
4 changes: 2 additions & 2 deletions tests/Unit/ScoutSearchCommandBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public function test_it_can_set_the_sort_order(): void
$command->setSort([new Sort('id', 'invalid')]);
}

public function test_it_only_accepts_syntax_interface_classes(): void
public function test_it_only_accepts_sort_classes(): void
{
$command = new ScoutSearchCommandBuilder();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected an instance of JeroenG\Explorer\Domain\Syntax\SyntaxInterface. Got: string');
$this->expectExceptionMessage('Expected an instance of JeroenG\Explorer\Domain\Syntax\Sort. Got: string');

$command->setSort(['not' => 'a class']);
}
Expand Down

0 comments on commit e39853f

Please sign in to comment.