|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Rb\Specification\Doctrine\Condition; |
| 4 | + |
| 5 | +use Doctrine\ORM\Query\Expr; |
| 6 | +use Doctrine\ORM\QueryBuilder; |
| 7 | +use PhpSpec\ObjectBehavior; |
| 8 | +use Rb\Specification\Doctrine\SpecificationInterface; |
| 9 | + |
| 10 | +class IsMemberOfSpec extends ObjectBehavior |
| 11 | +{ |
| 12 | + private $className = '\Foo'; |
| 13 | + private $field = 'foo'; |
| 14 | + |
| 15 | + private $dqlAlias = 'a'; |
| 16 | + |
| 17 | + public function let() |
| 18 | + { |
| 19 | + $this->beConstructedWith($this->field, $this->className, $this->dqlAlias); |
| 20 | + } |
| 21 | + |
| 22 | + public function it_is_an_expression() |
| 23 | + { |
| 24 | + $this->shouldBeAnInstanceOf(SpecificationInterface::class); |
| 25 | + } |
| 26 | + |
| 27 | + public function it_calls_is_instance_of(QueryBuilder $queryBuilder, Expr $expr) |
| 28 | + { |
| 29 | + $expression = 'a.foo member of ' . $this->className; |
| 30 | + |
| 31 | + $queryBuilder->expr()->willReturn($expr); |
| 32 | + $expr->isMemberOf(sprintf('%s.%s', $this->dqlAlias, $this->field), $this->className)->willReturn($expression); |
| 33 | + |
| 34 | + $this->isSatisfiedBy('foo')->shouldReturn(true); |
| 35 | + $this->modify($queryBuilder, 'b')->shouldReturn($expression); |
| 36 | + } |
| 37 | + |
| 38 | + public function it_uses_dql_alias_if_passed(QueryBuilder $queryBuilder, Expr $expr) |
| 39 | + { |
| 40 | + $dqlAlias = 'x'; |
| 41 | + $this->beConstructedWith($this->field, $this->className, null); |
| 42 | + $queryBuilder->expr()->willReturn($expr); |
| 43 | + |
| 44 | + $expr->isMemberOf(sprintf('%s.%s', $dqlAlias, $this->field), $this->className)->shouldBeCalled(); |
| 45 | + |
| 46 | + $this->isSatisfiedBy('foo')->shouldReturn(true); |
| 47 | + $this->modify($queryBuilder, $dqlAlias); |
| 48 | + } |
| 49 | +} |
0 commit comments