Skip to content

Commit

Permalink
Fix 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasruunu committed Jul 3, 2024
1 parent 354ee8b commit 4af94e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
22 changes: 9 additions & 13 deletions spec/Query/GroupBySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,36 @@

class GroupBySpec extends ObjectBehavior
{
private string $alias = 'a';

private string $field = 'foo';
private string $field = 'a.foo';

public function it_should_support_anything(): void
{
$this->beConstructedWith($this->field, GroupBy::ADD_GROUP_BY, $this->alias);
$this->beConstructedWith($this->field, GroupBy::ADD_GROUP_BY);

$this->isSatisfiedBy('foo')->shouldReturn(true);
}

public function it_calls_groupBy_on_query_builder(QueryBuilder $queryBuilder): void
{
$this->beConstructedWith($this->field, GroupBy::GROUP_BY, $this->alias);
$this->beConstructedWith($this->field, GroupBy::GROUP_BY);

$arg = sprintf('%s.%s', $this->alias, $this->field);
$queryBuilder->groupBy($arg)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->groupBy($this->field)->shouldBeCalled()->willReturn($queryBuilder);

$this->modify($queryBuilder, $this->alias);
$this->modify($queryBuilder);
}

public function it_calls_addGroupBy_on_query_builder(QueryBuilder $queryBuilder): void
{
$this->beConstructedWith($this->field, GroupBy::ADD_GROUP_BY, $this->alias);
$this->beConstructedWith($this->field, GroupBy::ADD_GROUP_BY);

$arg = sprintf('%s.%s', $this->alias, $this->field);
$queryBuilder->addGroupBy($arg)->shouldBeCalled()->willReturn($queryBuilder);
$queryBuilder->addGroupBy($this->field)->shouldBeCalled()->willReturn($queryBuilder);

$this->modify($queryBuilder, $this->alias);
$this->modify($queryBuilder);
}

public function it_throws_exception_when_setting_illegal_type(): void
{
$this->beConstructedWith($this->field, 'foo', $this->alias);
$this->beConstructedWith($this->field, 'foo');
$this->shouldThrow(InvalidArgumentException::class)->duringInstantiation();
}
}
8 changes: 0 additions & 8 deletions src/Query/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public function __construct(string $field, protected string $type = self::ADD_GR
}
}

/**
* @throws InvalidArgumentException
*/
public function setType(string $type): self
{
return new self($this->field, $type, $this->dqlAlias);
}

#[\Override]
public function modify(QueryBuilder $queryBuilder, ?string $dqlAlias = null): ?string
{
Expand Down
2 changes: 1 addition & 1 deletion src/SpecificationRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function modifyQueryBuilder(QueryBuilder $queryBuilder, SpecificationInt
{
$condition = $specification->modify($queryBuilder, $this->dqlAlias);

if (null === $condition || '' === $condition || '0' === $condition) {
if (null === $condition) {
return;
}

Expand Down

0 comments on commit 4af94e1

Please sign in to comment.