diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index f7fadd11..c66ed59d 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -17,7 +17,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.1 coverage: none tools: cs2pr, phpstan, composer:v2 @@ -42,7 +42,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.1 coverage: none tools: cs2pr, php-cs-fixer diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6816099c..542f0d33 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,28 +14,11 @@ jobs: - lowest - highest php-version: - - '7.2' - - '7.3' - - '7.4' - - '8.0' + - '8.1' - '8.2' + - '8.3' + - '8.4' variant: [normal] - include: - - php-version: '7.2' - dependencies: highest - variant: 'doctrine/orm:~2.5' - - php-version: '7.2' - dependencies: highest - variant: 'doctrine/orm:~2.6' - - php-version: '7.2' - dependencies: highest - variant: 'doctrine/orm:~2.7' - - php-version: '8.0' - dependencies: highest - variant: 'doctrine/orm:~2.7 symfony/property-access:^6.0' - - php-version: '8.2' - dependencies: highest - variant: 'doctrine/orm:~2.7 symfony/property-access:^7.0' steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 02419593..a9290a1d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /.php_cs /.php_cs.cache /.php-cs-fixer.cache +/.idea diff --git a/composer.json b/composer.json index a4b622a6..ad1b4c4c 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,9 @@ } ], "require": { - "php": ">=7.2", - "doctrine/orm": "~2.5", - "symfony/property-access": "^4.0 || ^5.2 || ^6.0 || ^7.0", - "symfony/polyfill-php80": "^1.20" + "php": ">=8.1", + "doctrine/orm": "^3.0", + "symfony/property-access": "^5.2 || ^6.0 || ^7.0" }, "require-dev": { "phpspec/phpspec": "~6.3 || ^7.0" diff --git a/src/DBALTypesResolver.php b/src/DBALTypesResolver.php index e639c557..60aaaf90 100644 --- a/src/DBALTypesResolver.php +++ b/src/DBALTypesResolver.php @@ -52,7 +52,7 @@ public static function tryGetTypeForValue($value): ?Type $classNameParts = explode('\\', str_replace('_', '\\', $className)); $typeName = array_pop($classNameParts); - if (null !== $typeName && array_key_exists($typeName, Type::getTypesMap())) { + if (null !== $typeName && Type::hasType($typeName)) { return Type::getType($typeName); } diff --git a/src/Repository/EntitySpecificationRepositoryTrait.php b/src/Repository/EntitySpecificationRepositoryTrait.php index 3f7d15b6..cf46640d 100644 --- a/src/Repository/EntitySpecificationRepositoryTrait.php +++ b/src/Repository/EntitySpecificationRepositoryTrait.php @@ -178,13 +178,7 @@ public function iterate($specification, ?ResultModifier $modifier = null): \Trav { $query = $this->getQuery($specification, $modifier); - if (method_exists($query, 'toIterable')) { - yield from $query->toIterable(); - } else { - foreach ($query->iterate() as $key => $row) { - yield $key => current($row); - } - } + yield from $query->toIterable(); } /** diff --git a/src/Result/Cache.php b/src/Result/Cache.php index 58e38e93..67d4f7cd 100644 --- a/src/Result/Cache.php +++ b/src/Result/Cache.php @@ -36,6 +36,6 @@ public function __construct(int $cacheLifetime) */ public function modify(AbstractQuery $query): void { - $query->setResultCacheLifetime($this->cacheLifetime); + $query->enableResultCache($this->cacheLifetime); } } diff --git a/tests/Filter/EqualsSpec.php b/tests/Filter/EqualsSpec.php index e4dc7d0a..1a955591 100644 --- a/tests/Filter/EqualsSpec.php +++ b/tests/Filter/EqualsSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('gender', 'F', null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -95,7 +95,7 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('gender', 'F', null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); @@ -140,8 +140,8 @@ public function it_filter_array_collection_in_context(): void $releaseAt = new \DateTimeImmutable(); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -155,8 +155,8 @@ public function it_filter_array_collection_in_global_context(): void $releaseAt = new \DateTimeImmutable(); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -181,8 +181,8 @@ public function it_filter_array_collection_in_combo_context(): void $owner = ['name' => 'ABC', 'based' => 123]; $game = ['name' => 'Tetris', 'owner' => $owner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; diff --git a/tests/Filter/GreaterOrEqualThanSpec.php b/tests/Filter/GreaterOrEqualThanSpec.php index 7bc9df19..ca6e4d9f 100644 --- a/tests/Filter/GreaterOrEqualThanSpec.php +++ b/tests/Filter/GreaterOrEqualThanSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('points', 9000, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9000], ]; @@ -95,8 +95,8 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('points', 2500, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(true); @@ -144,8 +144,8 @@ public function it_filter_array_collection_in_context(): void $releaseAt = new \DateTimeImmutable(); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -159,8 +159,8 @@ public function it_filter_array_collection_in_global_context(): void $releaseAt = new \DateTimeImmutable(); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -185,8 +185,8 @@ public function it_filter_array_collection_in_combo_context(): void $owner = ['name' => 'ABC', 'based' => 123]; $game = ['name' => 'Tetris', 'owner' => $owner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; diff --git a/tests/Filter/GreaterThanSpec.php b/tests/Filter/GreaterThanSpec.php index 1d5fa45c..ede05e9d 100644 --- a/tests/Filter/GreaterThanSpec.php +++ b/tests/Filter/GreaterThanSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('points', 9000, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -95,8 +95,8 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('points', 2500, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); @@ -147,8 +147,8 @@ public function it_filter_array_collection_in_context(): void $releaseAt = new \DateTimeImmutable('+1 day'); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -163,8 +163,8 @@ public function it_filter_array_collection_in_global_context(): void $releaseAt = new \DateTimeImmutable('+1 day'); $game = ['name' => 'Tetris', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $game], ]; @@ -192,8 +192,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Filter/InSpec.php b/tests/Filter/InSpec.php index 08b0fd0c..b1d22322 100644 --- a/tests/Filter/InSpec.php +++ b/tests/Filter/InSpec.php @@ -16,6 +16,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\Expr\Func; use Doctrine\ORM\QueryBuilder; use Happyr\DoctrineSpecification\Filter\Filter; use Happyr\DoctrineSpecification\Filter\In; @@ -42,16 +43,17 @@ public function it_is_an_expression(): void $this->shouldBeAnInstanceOf(Filter::class); } - public function it_returns_expression_func_object(QueryBuilder $qb, ArrayCollection $parameters, Expr $expr): void + public function it_returns_expression_func_object(QueryBuilder $qb, ArrayCollection $parameters, Expr $expr, Func $func): void { $context = 'a'; $qb->expr()->willReturn($expr); - $expr->in(sprintf('%s.%s', $context, $this->field), ':comparison_10')->shouldBeCalled(); + $expr->in(sprintf('%s.%s', $context, $this->field), ':comparison_10')->willReturn($func); + $func->__toString()->willReturn('field IN (:comparison_10)'); $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, null)->willReturn($qb)->shouldBeCalled(); $this->getFilter($qb, 'a'); } @@ -61,8 +63,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('points', [1230, 2500], null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -86,8 +88,8 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('points', [1230, 2500], null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(true); @@ -132,8 +134,8 @@ public function it_filter_array_collection_in_context(): void { $tetris = ['name' => 'Tetris']; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -146,8 +148,8 @@ public function it_filter_array_collection_in_global_context(): void { $tetris = ['name' => 'Tetris']; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -173,8 +175,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Filter/LessOrEqualThanSpec.php b/tests/Filter/LessOrEqualThanSpec.php index 18fa970e..ff2ee701 100644 --- a/tests/Filter/LessOrEqualThanSpec.php +++ b/tests/Filter/LessOrEqualThanSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('points', 2500, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -95,8 +95,8 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('points', 2500, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(true); @@ -145,8 +145,8 @@ public function it_filter_array_collection_in_context(): void $tetris = ['name' => 'Tetris', 'releaseAt' => new \DateTimeImmutable('-1 day')]; $mahjong = ['name' => 'Mahjong', 'releaseAt' => new \DateTimeImmutable('+1 day')]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -161,8 +161,8 @@ public function it_filter_array_collection_in_global_context(): void $tetris = ['name' => 'Tetris', 'releaseAt' => new \DateTimeImmutable('-1 day')]; $mahjong = ['name' => 'Mahjong', 'releaseAt' => new \DateTimeImmutable('+1 day')]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -189,8 +189,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Filter/LessThanSpec.php b/tests/Filter/LessThanSpec.php index b2a30181..b0d94803 100644 --- a/tests/Filter/LessThanSpec.php +++ b/tests/Filter/LessThanSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('points', 2500, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -95,8 +95,8 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('points', 2500, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); @@ -147,8 +147,8 @@ public function it_filter_array_collection_in_context(): void $tetris = ['name' => 'Tetris', 'releaseAt' => new \DateTimeImmutable('-1 day')]; $mahjong = ['name' => 'Mahjong', 'releaseAt' => new \DateTimeImmutable('+1 day')]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -163,8 +163,8 @@ public function it_filter_array_collection_in_global_context(): void $tetris = ['name' => 'Tetris', 'releaseAt' => new \DateTimeImmutable('-1 day')]; $mahjong = ['name' => 'Mahjong', 'releaseAt' => new \DateTimeImmutable('+1 day')]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -192,8 +192,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Filter/LikeSpec.php b/tests/Filter/LikeSpec.php index d40af8b1..a16fce04 100644 --- a/tests/Filter/LikeSpec.php +++ b/tests/Filter/LikeSpec.php @@ -49,7 +49,7 @@ public function it_surrounds_with_wildcards_when_using_contains( $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', '%bar%')->shouldBeCalled(); + $qb->setParameter('comparison_1', '%bar%')->willReturn($qb)->shouldBeCalled(); $this->getFilter($qb, 'a'); } @@ -62,7 +62,7 @@ public function it_surrounds_with_wildcards_when_using_contains_in_context( $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', '%bar%')->shouldBeCalled(); + $qb->setParameter('comparison_1', '%bar%')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -77,7 +77,7 @@ public function it_starts_with_wildcard_when_using_ends_with(QueryBuilder $qb, A $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', '%bar')->shouldBeCalled(); + $qb->setParameter('comparison_1', '%bar')->willReturn($qb)->shouldBeCalled(); $this->getFilter($qb, 'a'); } @@ -91,7 +91,7 @@ public function it_starts_with_wildcard_when_using_ends_with_in_context( $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', '%bar')->shouldBeCalled(); + $qb->setParameter('comparison_1', '%bar')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -106,7 +106,7 @@ public function it_ends_with_wildcard_when_using_starts_with(QueryBuilder $qb, A $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', 'bar%')->shouldBeCalled(); + $qb->setParameter('comparison_1', 'bar%')->willReturn($qb)->shouldBeCalled(); $this->getFilter($qb, 'a'); } @@ -120,7 +120,7 @@ public function it_ends_with_wildcard_when_using_starts_with_in_context( $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(1); - $qb->setParameter('comparison_1', 'bar%')->shouldBeCalled(); + $qb->setParameter('comparison_1', 'bar%')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -134,8 +134,8 @@ public function it_filter_array_collection_starts_with(): void $this->beConstructedWith('pseudo', 'M', Like::STARTS_WITH, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -147,8 +147,8 @@ public function it_filter_array_collection_ends_with(): void $this->beConstructedWith('pseudo', 'oe', Like::ENDS_WITH, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -160,8 +160,8 @@ public function it_filter_array_collection_contains(): void $this->beConstructedWith('pseudo', 'o', Like::CONTAINS, null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -211,7 +211,7 @@ public function it_is_satisfied_with_array_starts_with(): void { $this->beConstructedWith('pseudo', 'A', Like::STARTS_WITH, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); @@ -222,7 +222,7 @@ public function it_is_satisfied_with_array_ends_with(): void { $this->beConstructedWith('pseudo', 'oe', Like::ENDS_WITH, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(true); @@ -233,7 +233,7 @@ public function it_is_satisfied_with_array_contains(): void { $this->beConstructedWith('pseudo', 'oe', Like::CONTAINS, null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(true); @@ -298,8 +298,8 @@ public function it_filter_array_collection_in_context(): void $tetris = ['name' => 'Tetris']; $mahjong = ['name' => 'Mahjong']; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -314,8 +314,8 @@ public function it_filter_array_collection_in_global_context(): void $tetris = ['name' => 'Tetris', 'releaseAt' => null]; $mahjong = ['name' => 'Mahjong', 'releaseAt' => $releaseAt]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -341,8 +341,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Filter/MemberOfXSpec.php b/tests/Filter/MemberOfXSpec.php index ec26bb16..c8fc91e7 100644 --- a/tests/Filter/MemberOfXSpec.php +++ b/tests/Filter/MemberOfXSpec.php @@ -49,7 +49,7 @@ public function it_returns_expression_func_object(QueryBuilder $qb, ArrayCollect $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $exp->isMemberOf(':comparison_10', 'a.age')->willReturn($exp_comparison); $this->getFilter($qb, 'a')->shouldReturn(':comparison_10 MEMBER OF a.age'); @@ -67,7 +67,7 @@ public function it_returns_expression_func_object_in_context( $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $exp->isMemberOf(':comparison_10', 'user.age')->willReturn($exp_comparison); $qb->getDQLPart('join')->willReturn([]); diff --git a/tests/Filter/NotEqualsSpec.php b/tests/Filter/NotEqualsSpec.php index 49681525..105bf86f 100644 --- a/tests/Filter/NotEqualsSpec.php +++ b/tests/Filter/NotEqualsSpec.php @@ -42,7 +42,7 @@ public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $comparison = $this->getFilter($qb, 'a'); @@ -56,7 +56,7 @@ public function it_returns_comparison_object_in_context(QueryBuilder $qb, ArrayC $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 18, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 18, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -70,8 +70,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith('gender', 'M', null); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -95,7 +95,7 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith('gender', 'M', null); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); @@ -138,8 +138,8 @@ public function it_filter_array_collection_in_context(): void $tetris = ['name' => 'Tetris']; $mahjong = ['name' => 'Mahjong']; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -153,8 +153,8 @@ public function it_filter_array_collection_in_global_context(): void $tetris = ['name' => 'Tetris']; $mahjong = ['name' => 'Mahjong']; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; @@ -180,8 +180,8 @@ public function it_filter_array_collection_in_combo_context(): void $tetris = ['name' => 'Tetris', 'owner' => $tetrisOwner]; $mahjong = ['name' => 'Mahjong', 'owner' => $mahjongOwner]; $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500, 'inGame' => $mahjong], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230, 'inGame' => $mahjong], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001, 'inGame' => $tetris], ]; diff --git a/tests/Logic/AndXSpec.php b/tests/Logic/AndXSpec.php index 048e1c66..316fb25b 100644 --- a/tests/Logic/AndXSpec.php +++ b/tests/Logic/AndXSpec.php @@ -15,6 +15,7 @@ namespace tests\Happyr\DoctrineSpecification\Logic; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\Expr\Andx as ExprAndx; use Doctrine\ORM\QueryBuilder; use Happyr\DoctrineSpecification\Filter\Equals; use Happyr\DoctrineSpecification\Filter\Filter; @@ -57,6 +58,7 @@ public function it_modifies_all_child_queries( public function it_composes_and_child_with_expression( QueryBuilder $qb, Expr $expression, + ExprAndx $andX, Specification $specificationA, Specification $specificationB ): void { @@ -68,12 +70,13 @@ public function it_composes_and_child_with_expression( $specificationB->getFilter($qb, $context)->willReturn($filterB); $qb->expr()->willReturn($expression); - $expression->andX($filterA, $filterB)->shouldBeCalled(); + $expression->andX($filterA, $filterB)->willReturn($andX); + $andX->__toString()->willReturn('foo AND bar'); $this->getFilter($qb, $context); } - public function it_supports_expressions(QueryBuilder $qb, Expr $expression, Filter $exprA, Filter $exprB): void + public function it_supports_expressions(QueryBuilder $qb, Expr $expression, ExprAndx $andX, Filter $exprA, Filter $exprB): void { $this->beConstructedWith($exprA, $exprB); @@ -85,7 +88,8 @@ public function it_supports_expressions(QueryBuilder $qb, Expr $expression, Filt $exprB->getFilter($qb, $context)->willReturn($filterB); $qb->expr()->willReturn($expression); - $expression->andX($filterA, $filterB)->shouldBeCalled(); + $expression->andX($filterA, $filterB)->willReturn($andX); + $andX->__toString()->willReturn('foo AND bar'); $this->getFilter($qb, $context); } @@ -98,8 +102,8 @@ public function it_filter_array_collection(): void ); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -127,8 +131,8 @@ public function it_filter_array_collection_not_satisfiable(Filter $exprA, Filter $this->beConstructedWith($exprA, $exprB); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -155,7 +159,7 @@ public function it_is_satisfied_with_array(): void new GreaterThan('points', 9000) ); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); diff --git a/tests/Logic/NotSpec.php b/tests/Logic/NotSpec.php index f2e80dfb..c1fa5cfe 100644 --- a/tests/Logic/NotSpec.php +++ b/tests/Logic/NotSpec.php @@ -15,6 +15,7 @@ namespace tests\Happyr\DoctrineSpecification\Logic; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\Expr\Func; use Doctrine\ORM\QueryBuilder; use Happyr\DoctrineSpecification\Filter\Equals; use Happyr\DoctrineSpecification\Filter\Filter; @@ -37,7 +38,7 @@ public function let(Filter $filterExpr): void /** * calls parent. */ - public function it_calls_parent_match(QueryBuilder $qb, Expr $expr, Filter $filterExpr): void + public function it_calls_parent_match(QueryBuilder $qb, Expr $expr, Func $func, Filter $filterExpr): void { $context = 'a'; $expression = 'expression'; @@ -46,7 +47,8 @@ public function it_calls_parent_match(QueryBuilder $qb, Expr $expr, Filter $filt $qb->expr()->willReturn($expr); $filterExpr->getFilter($qb, $context)->willReturn($parentExpression); - $expr->not($parentExpression)->willReturn($expression); + $expr->not($parentExpression)->willReturn($func); + $func->__toString()->willReturn($expression); $this->getFilter($qb, $context)->shouldReturn($expression); } @@ -72,8 +74,8 @@ public function it_filter_array_collection(): void $this->beConstructedWith(new Equals('gender', 'M')); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -98,8 +100,8 @@ public function it_filter_array_collection_not_satisfiable(Filter $expr): void $this->beConstructedWith($expr); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -123,7 +125,7 @@ public function it_is_satisfied_with_array(): void { $this->beConstructedWith(new Equals('gender', 'M')); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; $playerB = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001]; $this->isSatisfiedBy($playerA)->shouldBe(false); diff --git a/tests/Logic/OrXSpec.php b/tests/Logic/OrXSpec.php index 77b5d859..d8173881 100644 --- a/tests/Logic/OrXSpec.php +++ b/tests/Logic/OrXSpec.php @@ -15,6 +15,7 @@ namespace tests\Happyr\DoctrineSpecification\Logic; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\Expr\Orx as ExprOrx; use Doctrine\ORM\QueryBuilder; use Happyr\DoctrineSpecification\Filter\Equals; use Happyr\DoctrineSpecification\Filter\Filter; @@ -56,6 +57,7 @@ public function it_modifies_all_child_queries( public function it_composes_and_child_with_expression( QueryBuilder $qb, Expr $expression, + ExprOrx $orX, Specification $specificationA, Specification $specificationB ): void { @@ -67,7 +69,8 @@ public function it_composes_and_child_with_expression( $specificationB->getFilter($qb, $context)->willReturn($filterB); $qb->expr()->willReturn($expression); - $expression->orX($filterA, $filterB)->shouldBeCalled(); + $expression->orX($filterA, $filterB)->willReturn($orX); + $orX->__toString()->willReturn('foo OR bar'); $this->getFilter($qb, $context); } @@ -75,6 +78,7 @@ public function it_composes_and_child_with_expression( public function it_supports_expressions( QueryBuilder $qb, Expr $expression, + ExprOrx $orX, Filter $exprA, Filter $exprB ): void { @@ -88,7 +92,8 @@ public function it_supports_expressions( $exprB->getFilter($qb, $context)->willReturn($filterB); $qb->expr()->willReturn($expression); - $expression->orX($filterA, $filterB)->shouldBeCalled(); + $expression->orX($filterA, $filterB)->willReturn($orX); + $orX->__toString()->willReturn('foo OR bar'); $this->getFilter($qb, $context); } @@ -101,8 +106,8 @@ public function it_filter_array_collection(): void ); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 9001], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 9001], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 1230], ]; @@ -130,8 +135,8 @@ public function it_filter_array_collection_not_satisfiable(Filter $exprA, Filter $this->beConstructedWith($exprA, $exprB); $players = [ - ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], - ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], + ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500], + ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 1230], ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 9001], ]; @@ -158,8 +163,8 @@ public function it_is_satisfied_with_array(): void new GreaterThan('points', 9000) ); - $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; - $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 9001]; + $playerA = ['pseudo' => 'Joe', 'gender' => 'M', 'points' => 2500]; + $playerB = ['pseudo' => 'Moe', 'gender' => 'M', 'points' => 9001]; $playerC = ['pseudo' => 'Alice', 'gender' => 'F', 'points' => 1230]; $this->isSatisfiedBy($playerA)->shouldBe(false); diff --git a/tests/Operand/AdditionSpec.php b/tests/Operand/AdditionSpec.php index 35f122ef..d47b4202 100644 --- a/tests/Operand/AdditionSpec.php +++ b/tests/Operand/AdditionSpec.php @@ -52,7 +52,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn('(a.foo + :comparison_10)'); } diff --git a/tests/Operand/DivisionSpec.php b/tests/Operand/DivisionSpec.php index b2a06191..5908122e 100644 --- a/tests/Operand/DivisionSpec.php +++ b/tests/Operand/DivisionSpec.php @@ -52,7 +52,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn('(a.foo / :comparison_10)'); } diff --git a/tests/Operand/LikePatternSpec.php b/tests/Operand/LikePatternSpec.php index 4e5044c4..25a6ca72 100644 --- a/tests/Operand/LikePatternSpec.php +++ b/tests/Operand/LikePatternSpec.php @@ -51,7 +51,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', sprintf($this->format, $this->value))->shouldBeCalled(); + $qb->setParameter('comparison_10', sprintf($this->format, $this->value))->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn(':comparison_10'); } diff --git a/tests/Operand/MultiplicationSpec.php b/tests/Operand/MultiplicationSpec.php index 3d702382..0433d859 100644 --- a/tests/Operand/MultiplicationSpec.php +++ b/tests/Operand/MultiplicationSpec.php @@ -52,7 +52,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn('(a.foo * :comparison_10)'); } diff --git a/tests/Operand/PlatformFunctionSpec.php b/tests/Operand/PlatformFunctionSpec.php index 7a9c4c07..1a9ec58c 100644 --- a/tests/Operand/PlatformFunctionSpec.php +++ b/tests/Operand/PlatformFunctionSpec.php @@ -159,8 +159,8 @@ public function it_is_transformable_convertible( $qb->getEntityManager()->willReturn($em); $qb->getParameters()->willReturn($parameters); - $qb->setParameter('comparison_10', 'bar', null)->shouldBeCalled(); - $qb->setParameter('comparison_11', 'baz', null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 'bar', null)->willReturn($qb)->shouldBeCalled(); + $qb->setParameter('comparison_11', 'baz', null)->willReturn($qb)->shouldBeCalled(); $em->getConfiguration()->willReturn($configuration); diff --git a/tests/Operand/SubtractionSpec.php b/tests/Operand/SubtractionSpec.php index 701436ef..e85e609e 100644 --- a/tests/Operand/SubtractionSpec.php +++ b/tests/Operand/SubtractionSpec.php @@ -52,7 +52,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn('(a.foo - :comparison_10)'); } diff --git a/tests/Operand/ValueSpec.php b/tests/Operand/ValueSpec.php index cd56eafe..28d6edc9 100644 --- a/tests/Operand/ValueSpec.php +++ b/tests/Operand/ValueSpec.php @@ -51,7 +51,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, $this->valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, $this->valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn(':comparison_10'); } @@ -64,7 +64,7 @@ public function it_is_transformable_dbal_type(QueryBuilder $qb, ArrayCollection $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, $valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, $valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn(':comparison_10'); } @@ -77,7 +77,7 @@ public function it_is_transformable_pdo_type(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->value, $valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->value, $valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn(':comparison_10'); } diff --git a/tests/Operand/ValuesSpec.php b/tests/Operand/ValuesSpec.php index 7d2e5a6f..a747ec08 100644 --- a/tests/Operand/ValuesSpec.php +++ b/tests/Operand/ValuesSpec.php @@ -51,7 +51,7 @@ public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameter $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->values, $this->valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->values, $this->valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn(':comparison_10'); } @@ -64,7 +64,7 @@ public function it_is_transformable_dbal_type(QueryBuilder $qb, ArrayCollection $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->values, $valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->values, $valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn(':comparison_10'); } @@ -77,7 +77,7 @@ public function it_is_transformable_pdo_type(QueryBuilder $qb, ArrayCollection $ $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', $this->values, $valueType)->shouldBeCalled(); + $qb->setParameter('comparison_10', $this->values, $valueType)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, 'a')->shouldReturn(':comparison_10'); } diff --git a/tests/Query/AddSelectSpec.php b/tests/Query/AddSelectSpec.php index 5227e592..e277d2f0 100644 --- a/tests/Query/AddSelectSpec.php +++ b/tests/Query/AddSelectSpec.php @@ -42,21 +42,21 @@ public function it_is_a_query_modifier(): void public function it_add_select_single_filed(QueryBuilder $qb): void { - $qb->addSelect(['a.foo'])->shouldBeCalled(); + $qb->addSelect(['a.foo'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } public function it_add_select_several_fields(QueryBuilder $qb): void { $this->beConstructedWith('foo', 'bar'); - $qb->addSelect(['b.foo', 'b.bar'])->shouldBeCalled(); + $qb->addSelect(['b.foo', 'b.bar'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'b'); } public function it_add_select_operand(QueryBuilder $qb): void { $this->beConstructedWith('foo', new Field('bar')); - $qb->addSelect(['b.foo', 'b.bar'])->shouldBeCalled(); + $qb->addSelect(['b.foo', 'b.bar'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'b'); } } diff --git a/tests/Query/DistinctSpec.php b/tests/Query/DistinctSpec.php index d37b2a13..22cd7b52 100644 --- a/tests/Query/DistinctSpec.php +++ b/tests/Query/DistinctSpec.php @@ -36,7 +36,7 @@ public function it_is_a_query_modifier(): void public function it_add_having(QueryBuilder $qb): void { - $qb->distinct()->shouldBeCalled(); + $qb->distinct()->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } } diff --git a/tests/Query/HavingSpec.php b/tests/Query/HavingSpec.php index 353fe88c..e346de6d 100644 --- a/tests/Query/HavingSpec.php +++ b/tests/Query/HavingSpec.php @@ -44,7 +44,7 @@ public function it_add_having(QueryBuilder $qb, Filter $filter): void { $this->beConstructedWith($filter); $filter->getFilter($qb, 'a')->willReturn('foo = :bar'); - $qb->having('foo = :bar')->shouldBeCalled(); + $qb->having('foo = :bar')->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } } diff --git a/tests/Query/IndexBySpec.php b/tests/Query/IndexBySpec.php index 4e9a1245..a4ba0f33 100644 --- a/tests/Query/IndexBySpec.php +++ b/tests/Query/IndexBySpec.php @@ -40,7 +40,7 @@ public function it_is_a_query_modifier(): void public function it_indexes(QueryBuilder $qb): void { - $qb->indexBy('a', sprintf('a.%s', $this->field))->shouldBeCalled(); + $qb->indexBy('a', sprintf('a.%s', $this->field))->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -49,7 +49,7 @@ public function it_indexes_in_context(QueryBuilder $qb): void { $this->beConstructedWith('thing', 'user'); - $qb->indexBy('user', 'user.thing')->shouldBeCalled(); + $qb->indexBy('user', 'user.thing')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); diff --git a/tests/Query/InnerJoinSpec.php b/tests/Query/InnerJoinSpec.php index e12042c4..e6c00a28 100644 --- a/tests/Query/InnerJoinSpec.php +++ b/tests/Query/InnerJoinSpec.php @@ -36,7 +36,7 @@ public function it_is_a_query_modifier(): void public function it_joins_with_default_dql_alias(QueryBuilder $qb): void { - $qb->innerJoin('a.user', 'authUser')->shouldBeCalled(); + $qb->innerJoin('a.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -45,7 +45,7 @@ public function it_joins_in_context(QueryBuilder $qb): void { $this->beConstructedWith('user', 'authUser', 'x'); - $qb->innerJoin('x.user', 'authUser')->shouldBeCalled(); + $qb->innerJoin('x.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); diff --git a/tests/Query/JoinSpec.php b/tests/Query/JoinSpec.php index cf87df02..97892c14 100644 --- a/tests/Query/JoinSpec.php +++ b/tests/Query/JoinSpec.php @@ -36,7 +36,7 @@ public function it_is_a_query_modifier(): void public function it_joins_with_default_dql_alias(QueryBuilder $qb): void { - $qb->join('a.user', 'authUser')->shouldBeCalled(); + $qb->join('a.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -45,7 +45,7 @@ public function it_joins_in_context(QueryBuilder $qb): void { $this->beConstructedWith('user', 'authUser', 'x'); - $qb->join('x.user', 'authUser')->shouldBeCalled(); + $qb->join('x.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); diff --git a/tests/Query/LeftJoinSpec.php b/tests/Query/LeftJoinSpec.php index 18a2fc54..b6b0aa25 100644 --- a/tests/Query/LeftJoinSpec.php +++ b/tests/Query/LeftJoinSpec.php @@ -36,7 +36,7 @@ public function it_is_a_query_modifier(): void public function it_joins_with_default_dql_alias(QueryBuilder $qb): void { - $qb->leftJoin('a.user', 'authUser')->shouldBeCalled(); + $qb->leftJoin('a.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -45,7 +45,7 @@ public function it_joins_in_context(QueryBuilder $qb): void { $this->beConstructedWith('user', 'authUser', 'x'); - $qb->leftJoin('x.user', 'authUser')->shouldBeCalled(); + $qb->leftJoin('x.user', 'authUser')->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); diff --git a/tests/Query/SelectNewSpec.php b/tests/Query/SelectNewSpec.php index f6d206d8..1054e55b 100644 --- a/tests/Query/SelectNewSpec.php +++ b/tests/Query/SelectNewSpec.php @@ -46,7 +46,7 @@ public function it_is_a_query_modifier(): void public function it_select_empty_object(QueryBuilder $qb): void { - $qb->select(sprintf('NEW %s()', Player::class))->shouldBeCalled(); + $qb->select(sprintf('NEW %s()', Player::class))->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -55,7 +55,7 @@ public function it_select_with_field(QueryBuilder $qb): void { $this->beConstructedWith(Player::class, 'pseudo'); - $qb->select(sprintf('NEW %s(a.pseudo)', Player::class))->shouldBeCalled(); + $qb->select(sprintf('NEW %s(a.pseudo)', Player::class))->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -67,8 +67,8 @@ public function it_select_with_field_and_value(QueryBuilder $qb, ArrayCollection $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'F', null)->shouldBeCalled(); - $qb->select(sprintf('NEW %s(a.pseudo, :comparison_10)', Player::class))->shouldBeCalled(); + $qb->setParameter('comparison_10', 'F', null)->willReturn($qb)->shouldBeCalled(); + $qb->select(sprintf('NEW %s(a.pseudo, :comparison_10)', Player::class))->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -85,8 +85,8 @@ public function it_select_with_operands(QueryBuilder $qb, ArrayCollection $param $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'F', null)->shouldBeCalled(); - $qb->select(sprintf('NEW %s(a.pseudo, :comparison_10, (a.foo + a.bar))', Player::class))->shouldBeCalled(); + $qb->setParameter('comparison_10', 'F', null)->willReturn($qb)->shouldBeCalled(); + $qb->select(sprintf('NEW %s(a.pseudo, :comparison_10, (a.foo + a.bar))', Player::class))->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } diff --git a/tests/Query/SelectSpec.php b/tests/Query/SelectSpec.php index 51f0819a..602669c8 100644 --- a/tests/Query/SelectSpec.php +++ b/tests/Query/SelectSpec.php @@ -42,21 +42,21 @@ public function it_is_a_query_modifier(): void public function it_select_single_filed(QueryBuilder $qb): void { - $qb->select(['a.foo'])->shouldBeCalled(); + $qb->select(['a.foo'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } public function it_select_several_fields(QueryBuilder $qb): void { $this->beConstructedWith('foo', 'bar'); - $qb->select(['b.foo', 'b.bar'])->shouldBeCalled(); + $qb->select(['b.foo', 'b.bar'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'b'); } public function it_select_operand(QueryBuilder $qb): void { $this->beConstructedWith('foo', new Field('bar')); - $qb->select(['b.foo', 'b.bar'])->shouldBeCalled(); + $qb->select(['b.foo', 'b.bar'])->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'b'); } } diff --git a/tests/Query/Selection/SelectAsSpec.php b/tests/Query/Selection/SelectAsSpec.php index 0743de70..1b313835 100644 --- a/tests/Query/Selection/SelectAsSpec.php +++ b/tests/Query/Selection/SelectAsSpec.php @@ -76,7 +76,7 @@ public function it_is_transformable_value(QueryBuilder $qb, ArrayCollection $par $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'foo', null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 'foo', null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn($expression); } @@ -92,7 +92,7 @@ public function it_is_transformable_filter(QueryBuilder $qb, ArrayCollection $pa $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'bar', null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 'bar', null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn($expression); } diff --git a/tests/Query/Selection/SelectHiddenAsSpec.php b/tests/Query/Selection/SelectHiddenAsSpec.php index c26597e3..c7cf8c32 100644 --- a/tests/Query/Selection/SelectHiddenAsSpec.php +++ b/tests/Query/Selection/SelectHiddenAsSpec.php @@ -76,7 +76,7 @@ public function it_is_transformable_value(QueryBuilder $qb, ArrayCollection $par $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'foo', null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 'foo', null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn($expression); } @@ -92,7 +92,7 @@ public function it_is_transformable_filter(QueryBuilder $qb, ArrayCollection $pa $qb->getParameters()->willReturn($parameters); $parameters->count()->willReturn(10); - $qb->setParameter('comparison_10', 'bar', null)->shouldBeCalled(); + $qb->setParameter('comparison_10', 'bar', null)->willReturn($qb)->shouldBeCalled(); $this->transform($qb, $context)->shouldReturn($expression); } diff --git a/tests/Query/SliceSpec.php b/tests/Query/SliceSpec.php index c57977e1..41e07abe 100644 --- a/tests/Query/SliceSpec.php +++ b/tests/Query/SliceSpec.php @@ -43,7 +43,7 @@ public function it_slice_with_zero_index(QueryBuilder $qb): void { $this->beConstructedWith($this->sliceSize, 0); - $qb->setMaxResults($this->sliceSize)->shouldBeCalled(); + $qb->setMaxResults($this->sliceSize)->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } @@ -54,8 +54,8 @@ public function it_slice_with_second_index(QueryBuilder $qb): void $this->beConstructedWith($this->sliceSize, $sliceNumber); - $qb->setMaxResults($this->sliceSize)->shouldBeCalled(); - $qb->setFirstResult($this->sliceSize * $sliceNumber)->shouldBeCalled(); + $qb->setMaxResults($this->sliceSize)->willReturn($qb)->shouldBeCalled(); + $qb->setFirstResult($this->sliceSize * $sliceNumber)->willReturn($qb)->shouldBeCalled(); $this->modify($qb, 'a'); } diff --git a/tests/Repository/EntitySpecificationRepositorySpec.php b/tests/Repository/EntitySpecificationRepositorySpec.php index 867a7d9f..7b9b3bd6 100644 --- a/tests/Repository/EntitySpecificationRepositorySpec.php +++ b/tests/Repository/EntitySpecificationRepositorySpec.php @@ -14,9 +14,9 @@ namespace tests\Happyr\DoctrineSpecification\Repository; -use Doctrine\ORM\AbstractQuery; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query; use Doctrine\ORM\NonUniqueResultException as DoctrineNonUniqueResultException; use Doctrine\ORM\NoResultException as DoctrineNoResultException; use Doctrine\ORM\QueryBuilder; @@ -42,16 +42,16 @@ final class EntitySpecificationRepositorySpec extends ObjectBehavior private $result = 'result'; - public function let(EntityManager $entityManager, ClassMetadata $classMetadata): void + public function let(EntityManagerInterface $entityManager): void { - $this->beConstructedWith($entityManager, $classMetadata); + $this->beConstructedWith($entityManager, new ClassMetadata(Player::class)); } public function it_should_modify_query( QueryModifier $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareEntityManagerStub($entityManager, $qb); $this->prepareQueryBuilderStub($qb, $query); @@ -64,9 +64,9 @@ public function it_should_modify_query( public function it_should_apply_filter( Filter $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareEntityManagerStub($entityManager, $qb); $this->prepareQueryBuilderStub($qb, $query); @@ -80,9 +80,9 @@ public function it_should_apply_filter( } public function it_should_skip_apply_empty_specification( - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareEntityManagerStub($entityManager, $qb); $this->prepareQueryBuilderStub($qb, $query); @@ -95,9 +95,9 @@ public function it_should_skip_apply_empty_specification( public function it_matches_a_specification_with_empty_filter( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareEntityManagerStub($entityManager, $qb); $this->prepareQueryBuilderStub($qb, $query); @@ -114,9 +114,9 @@ public function it_matches_a_specification_with_empty_filter( public function it_matches_a_specification_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); $query->execute()->willReturn($this->result); @@ -128,9 +128,9 @@ public function it_matches_a_specification_without_result_modifier( public function it_matches_a_single_result_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $singleResult = new \stdClass(); @@ -145,9 +145,9 @@ public function it_matches_a_single_result_without_result_modifier( public function it_throws_exception_when_expecting_single_result_finding_none_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -160,9 +160,9 @@ public function it_throws_exception_when_expecting_single_result_finding_none_wi public function it_throws_exception_when_expecting_single_result_finding_multiple_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -175,9 +175,9 @@ public function it_throws_exception_when_expecting_single_result_finding_multipl public function it_matches_a_single_scalar_result_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $singleScalarResult = '1'; @@ -192,9 +192,9 @@ public function it_matches_a_single_scalar_result_without_result_modifier( public function it_throws_exception_when_expecting_single_scalar_result_finding_multiple_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -207,9 +207,9 @@ public function it_throws_exception_when_expecting_single_scalar_result_finding_ public function it_matches_a_scalar_result_when_expecting_one_or_null_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $scalarResult = ['1', '2', '3']; @@ -224,9 +224,9 @@ public function it_matches_a_scalar_result_when_expecting_one_or_null_without_re public function it_matches_a_single_result_when_expecting_one_or_null_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $singleResult = new \stdClass(); @@ -241,9 +241,9 @@ public function it_matches_a_single_result_when_expecting_one_or_null_without_re public function it_matches_null_when_expecting_one_or_null_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -256,9 +256,9 @@ public function it_matches_null_when_expecting_one_or_null_without_result_modifi public function it_throws_exception_when_expecting_one_or_null_finding_multiple_without_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -271,9 +271,9 @@ public function it_throws_exception_when_expecting_one_or_null_finding_multiple_ public function it_matches_a_specification_with_result_modifier( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query, + Query $query, ResultModifier $modifier ): void { $this->prepareStubs($specification, $entityManager, $qb, $query); @@ -287,16 +287,16 @@ public function it_matches_a_specification_with_result_modifier( private function prepareStubs( Specification $specification, - EntityManager $entityManager, + EntityManagerInterface $entityManager, QueryBuilder $qb, - AbstractQuery $query + Query $query ): void { $this->prepareEntityManagerStub($entityManager, $qb); $this->prepareSpecificationStub($specification, $qb); $this->prepareQueryBuilderStub($qb, $query); } - private function prepareEntityManagerStub(EntityManager $entityManager, QueryBuilder $qb): void + private function prepareEntityManagerStub(EntityManagerInterface $entityManager, QueryBuilder $qb): void { $entityManager->createQueryBuilder()->willReturn($qb); } @@ -306,7 +306,7 @@ private function prepareSpecificationStub(Specification $specification, QueryBui $specification->getFilter($qb, $this->alias)->willReturn($this->expression); } - private function prepareQueryBuilderStub(QueryBuilder $qb, AbstractQuery $query): void + private function prepareQueryBuilderStub(QueryBuilder $qb, Query $query): void { $qb->from(Argument::any(), $this->alias, null)->willReturn($qb); $qb->select($this->alias)->willReturn($qb); diff --git a/tests/Result/AsArraySpec.php b/tests/Result/AsArraySpec.php index 861acb7d..4cb4c061 100644 --- a/tests/Result/AsArraySpec.php +++ b/tests/Result/AsArraySpec.php @@ -32,7 +32,7 @@ public function it_is_a_result_modifier(): void public function it_sets_hydration_mode_to_array(AbstractQuery $query): void { - $query->setHydrationMode(Query::HYDRATE_ARRAY)->shouldBeCalled(); + $query->setHydrationMode(Query::HYDRATE_ARRAY)->willReturn($query)->shouldBeCalled(); $this->modify($query); } diff --git a/tests/Result/AsScalarSpec.php b/tests/Result/AsScalarSpec.php index e80cb391..8f6d84b2 100644 --- a/tests/Result/AsScalarSpec.php +++ b/tests/Result/AsScalarSpec.php @@ -32,7 +32,7 @@ public function it_is_a_result_modifier(): void public function it_sets_hydration_mode_to_object(AbstractQuery $query): void { - $query->setHydrationMode(Query::HYDRATE_SCALAR)->shouldBeCalled(); + $query->setHydrationMode(Query::HYDRATE_SCALAR)->willReturn($query)->shouldBeCalled(); $this->modify($query); } diff --git a/tests/Result/AsSingleScalarSpec.php b/tests/Result/AsSingleScalarSpec.php index 93c0df62..3396f543 100644 --- a/tests/Result/AsSingleScalarSpec.php +++ b/tests/Result/AsSingleScalarSpec.php @@ -32,7 +32,7 @@ public function it_is_a_result_modifier(): void public function it_sets_hydration_mode_to_object(AbstractQuery $query): void { - $query->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)->shouldBeCalled(); + $query->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)->willReturn($query)->shouldBeCalled(); $this->modify($query); } diff --git a/tests/Result/CacheSpec.php b/tests/Result/CacheSpec.php index 4cd469d7..61815957 100644 --- a/tests/Result/CacheSpec.php +++ b/tests/Result/CacheSpec.php @@ -38,7 +38,7 @@ public function it_is_a_specification(): void public function it_caches_query_for_given_time(AbstractQuery $query): void { - $query->setResultCacheLifetime($this->lifetime)->shouldBeCalled(); + $query->enableResultCache($this->lifetime)->willReturn($query)->shouldBeCalled(); $this->modify($query); } diff --git a/tests/Result/RoundDateTimeSpec.php b/tests/Result/RoundDateTimeSpec.php index cd32e572..1702ef8c 100644 --- a/tests/Result/RoundDateTimeSpec.php +++ b/tests/Result/RoundDateTimeSpec.php @@ -48,7 +48,7 @@ public function it_round_date_time_in_query_parameters_for_given_time(AbstractQu new Parameter('status', 'active'), // scalar param new Parameter($name, $actual, $type), ])); - $query->setParameter($name, $expected, $type)->shouldBeCalled(); + $query->setParameter($name, $expected, $type)->willReturn($query)->shouldBeCalled(); $this->modify($query); } diff --git a/tests/Specification/CountOfSpec.php b/tests/Specification/CountOfSpec.php index 965d68eb..1efcdd9f 100644 --- a/tests/Specification/CountOfSpec.php +++ b/tests/Specification/CountOfSpec.php @@ -46,7 +46,7 @@ public function it_count_of_all(QueryBuilder $qb): void { $context = 'a'; - $qb->select(sprintf('COUNT(%s)', $context))->shouldBeCalled(); + $qb->select(sprintf('COUNT(%s)', $context))->willReturn($qb)->shouldBeCalled(); $this->getFilter($qb, $context)->shouldBe(''); $this->modify($qb, $context); @@ -59,8 +59,8 @@ public function it_count_of_all_grouped_by_id(QueryBuilder $qb): void $this->beConstructedWith(new GroupBy($field, $context)); - $qb->select('COUNT(root)')->shouldBeCalled(); - $qb->addGroupBy(sprintf('%s.%s', $context, $field))->shouldBeCalled(); + $qb->select('COUNT(root)')->willReturn($qb)->shouldBeCalled(); + $qb->addGroupBy(sprintf('%s.%s', $context, $field))->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]); @@ -76,13 +76,13 @@ public function it_count_of_all_with_group_is_foo(QueryBuilder $qb): void $value = 'foo'; $context = 'user'; $parametersCount = 0; - $paramName = 'comparison_'.$parametersCount; + $paramName = 'comparison_' . $parametersCount; $this->beConstructedWith(new Equals($field, $value, $context)); - $qb->select('COUNT(root)')->shouldBeCalled(); + $qb->select('COUNT(root)')->willReturn($qb)->shouldBeCalled(); $qb->getParameters()->willReturn(new ArrayCollection()); - $qb->setParameter($paramName, $value, null)->shouldBeCalled(); + $qb->setParameter($paramName, $value, null)->willReturn($qb)->shouldBeCalled(); $qb->getDQLPart('join')->willReturn([]); $qb->getAllAliases()->willReturn([]);