1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of the Happyr Doctrine Specification package. |
6
|
|
|
* |
7
|
|
|
* (c) Tobias Nyholm <[email protected]> |
8
|
|
|
* Kacper Gunia <[email protected]> |
9
|
|
|
* Peter Gribanov <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace tests\Happyr\DoctrineSpecification\Query; |
16
|
|
|
|
17
|
|
|
use Doctrine\ORM\QueryBuilder; |
18
|
|
|
use Happyr\DoctrineSpecification\Query\IndexBy; |
19
|
|
|
use Happyr\DoctrineSpecification\Query\QueryModifier; |
20
|
|
|
use PhpSpec\ObjectBehavior; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @mixin IndexBy |
24
|
|
|
*/ |
25
|
|
|
final class IndexBySpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
private $field = 'the_field'; |
28
|
|
|
|
29
|
|
|
private $alias = 'f'; |
30
|
|
|
|
31
|
|
|
public function let(): void |
32
|
|
|
{ |
33
|
|
|
$this->beConstructedWith($this->field, null); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function it_is_a_query_modifier(): void |
37
|
|
|
{ |
38
|
|
|
$this->shouldBeAnInstanceOf(QueryModifier::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function it_indexes(QueryBuilder $qb): void |
42
|
|
|
{ |
43
|
|
|
$qb->indexBy('a', sprintf('a.%s', $this->field))->shouldBeCalled(); |
44
|
|
|
|
45
|
|
|
$this->modify($qb, 'a'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function it_indexes_in_context(QueryBuilder $qb): void |
49
|
|
|
{ |
50
|
|
|
$this->beConstructedWith('thing', 'user'); |
51
|
|
|
|
52
|
|
|
$qb->indexBy('user', 'user.thing')->shouldBeCalled(); |
53
|
|
|
|
54
|
|
|
$qb->getDQLPart('join')->willReturn([]); |
55
|
|
|
$qb->getAllAliases()->willReturn([]); |
56
|
|
|
$qb->join('root.user', 'user')->willReturn($qb); |
57
|
|
|
|
58
|
|
|
$this->modify($qb, 'root'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|