IndexBySpec::it_indexes_with_default_dql_alias()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace tests\Happyr\DoctrineSpecification\Query;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\Query\IndexBy;
18
use PhpSpec\ObjectBehavior;
19
use PhpSpec\Exception\Example\SkippingException;
20
21
/**
22
 * @mixin IndexBy
23
 */
24
class IndexBySpec extends ObjectBehavior
25
{
26
    private $field = 'the_field';
27
28
    private $alias = 'f';
29
30
    public function let()
31
    {
32
        $this->beConstructedWith($this->field, $this->alias);
33
    }
34
35
    public function it_is_a_result_modifier()
36
    {
37
        if (!method_exists(QueryBuilder::class, 'indexBy')) {
38
            throw new SkippingException('IndexBy query modifier require doctrine/orm >= 2.5');
39
        }
40
41
        $this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Query\QueryModifier');
42
    }
43
44 View Code Duplication
    public function it_indexes_with_default_dql_alias(QueryBuilder $qb)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        if (!method_exists(QueryBuilder::class, 'indexBy')) {
47
            throw new SkippingException('IndexBy query modifier require doctrine/orm >= 2.5');
48
        }
49
50
        $this->beConstructedWith('something', 'x');
51
        $qb->indexBy('x', 'x.something')->shouldBeCalled();
52
        $this->modify($qb, 'a');
53
    }
54
55 View Code Duplication
    public function it_uses_local_alias_if_global_was_not_set(QueryBuilder $qb)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        if (!method_exists(QueryBuilder::class, 'indexBy')) {
58
            throw new SkippingException('IndexBy query modifier require doctrine/orm >= 2.5');
59
        }
60
61
        $this->beConstructedWith('thing');
62
        $qb->indexBy('b', 'b.thing')->shouldBeCalled();
63
        $this->modify($qb, 'b');
64
    }
65
}
66