Skip to content

Commit

Permalink
Add support for doctrine/orm 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Feb 16, 2024
1 parent b9a152f commit 207abd0
Show file tree
Hide file tree
Showing 40 changed files with 105 additions and 103 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "happyr/doctrine-specification",
"name": "shlinkio/doctrine-specification",
"type": "library",
"description": "Specification Pattern for your Doctrine repositories",
"description": "Specification Pattern for your Doctrine repositories. Forked from https://github.com/Happyr/Doctrine-Specification",
"keywords": ["Doctrine", "Repository", "Specification"],
"homepage": "http://developer.happyr.com/",
"license": "MIT",
Expand All @@ -21,7 +21,7 @@
],
"require": {
"php": ">=8.2",
"doctrine/orm": "^2.18",
"doctrine/orm": "^3.0 || ^2.18",
"symfony/property-access": "^7.0 || ^6.0",
"symfony/polyfill-php80": "^1.20"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/EqualsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/GreaterOrEqualThanSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/GreaterThanSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
6 changes: 4 additions & 2 deletions tests/Filter/InSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public function it_returns_expression_func_object(QueryBuilder $qb, ArrayCollect
{
$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')->shouldBeCalled()->willReturn(
new Expr\Func($context . ' IN', (array) $this->field)
);

$qb->getParameters()->willReturn($parameters);
$parameters->count()->willReturn(10);

$qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled();
$qb->setParameter('comparison_10', $this->value, null)->shouldBeCalled()->willReturn($qb);

$this->getFilter($qb, 'a');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/LessOrEqualThanSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/LessThanSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
12 changes: 6 additions & 6 deletions tests/Filter/LikeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%')->shouldBeCalled()->willReturn($qb);

$this->getFilter($qb, 'a');
}
Expand All @@ -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%')->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand All @@ -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')->shouldBeCalled()->willReturn($qb);

$this->getFilter($qb, 'a');
}
Expand All @@ -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')->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand All @@ -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%')->shouldBeCalled()->willReturn($qb);

$this->getFilter($qb, 'a');
}
Expand All @@ -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%')->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/MemberOfXSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);
$exp->isMemberOf(':comparison_10', 'a.age')->willReturn($exp_comparison);

$this->getFilter($qb, 'a')->shouldReturn(':comparison_10 MEMBER OF a.age');
Expand All @@ -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)->shouldBeCalled()->willReturn($qb);
$exp->isMemberOf(':comparison_10', 'user.age')->willReturn($exp_comparison);

$qb->getDQLPart('join')->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Filter/NotEqualsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$comparison = $this->getFilter($qb, 'a');

Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$qb->getDQLPart('join')->willReturn([]);
$qb->getAllAliases()->willReturn([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Logic/AndXSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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)->shouldBeCalled()->willReturn(new Expr\Andx([$filterA, $filterB]));

$this->getFilter($qb, $context);
}
Expand All @@ -85,7 +85,7 @@ 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)->shouldBeCalled()->willReturn(new Expr\Andx([$filterA, $filterB]));

$this->getFilter($qb, $context);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Logic/NotSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ 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(new Expr\Func('NOT', [$expression]));

$this->getFilter($qb, $context)->shouldReturn($expression);
$this->getFilter($qb, $context)->shouldReturn('NOT(expression)');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Logic/OrXSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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)->shouldBeCalled()->willReturn(new Expr\Orx([$filterA, $filterB]));

$this->getFilter($qb, $context);
}
Expand All @@ -88,7 +88,7 @@ public function it_supports_expressions(
$exprB->getFilter($qb, $context)->willReturn($filterB);
$qb->expr()->willReturn($expression);

$expression->orX($filterA, $filterB)->shouldBeCalled();
$expression->orX($filterA, $filterB)->shouldBeCalled()->willReturn(new Expr\Orx([$filterA, $filterB]));

$this->getFilter($qb, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Operand/AdditionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn('(a.foo + :comparison_10)');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Operand/DivisionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn('(a.foo / :comparison_10)');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Operand/LikePatternSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))->shouldBeCalled()->willReturn($qb);

$this->transform($qb, $context)->shouldReturn(':comparison_10');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Operand/MultiplicationSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn('(a.foo * :comparison_10)');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Operand/PlatformFunctionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);
$qb->setParameter('comparison_11', 'baz', null)->shouldBeCalled()->willReturn($qb);

$em->getConfiguration()->willReturn($configuration);

Expand Down
2 changes: 1 addition & 1 deletion tests/Operand/SubtractionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn('(a.foo - :comparison_10)');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Operand/ValueSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, $context)->shouldReturn(':comparison_10');
}
Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn(':comparison_10');
}
Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn(':comparison_10');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Operand/ValuesSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, $context)->shouldReturn(':comparison_10');
}
Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn(':comparison_10');
}
Expand All @@ -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)->shouldBeCalled()->willReturn($qb);

$this->transform($qb, 'a')->shouldReturn(':comparison_10');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Query/AddSelectSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])->shouldBeCalled()->willReturn($qb);
$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'])->shouldBeCalled()->willReturn($qb);
$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'])->shouldBeCalled()->willReturn($qb);
$this->modify($qb, 'b');
}
}
Loading

0 comments on commit 207abd0

Please sign in to comment.