From 4af94e139906b98b71a89345521d631f49a25573 Mon Sep 17 00:00:00 2001 From: Nicholas Ruunu Date: Wed, 3 Jul 2024 10:51:32 +0200 Subject: [PATCH] Fix 100% coverage --- spec/Query/GroupBySpec.php | 22 +++++++++------------- src/Query/GroupBy.php | 8 -------- src/SpecificationRepositoryTrait.php | 2 +- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/spec/Query/GroupBySpec.php b/spec/Query/GroupBySpec.php index 90cc740..c2c80cf 100644 --- a/spec/Query/GroupBySpec.php +++ b/spec/Query/GroupBySpec.php @@ -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(); } } diff --git a/src/Query/GroupBy.php b/src/Query/GroupBy.php index e434e0a..3732706 100644 --- a/src/Query/GroupBy.php +++ b/src/Query/GroupBy.php @@ -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 { diff --git a/src/SpecificationRepositoryTrait.php b/src/SpecificationRepositoryTrait.php index 4ffe5f6..faa97d5 100644 --- a/src/SpecificationRepositoryTrait.php +++ b/src/SpecificationRepositoryTrait.php @@ -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; }