Completed
Push — 2.0 ( 33bb83...14462a )
by Peter
07:18 queued 16s
created

IndexBySpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_indexes() 0 6 1
A it_indexes_in_context() 0 12 1
A it_is_a_query_modifier() 0 4 1
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