Completed
Push — 2.0 ( f42152...9771bc )
by Peter
10:33 queued 12s
created

SelectEntitySpec::it_is_a_select_entity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Selection;
16
17
use Doctrine\ORM\QueryBuilder;
18
use Happyr\DoctrineSpecification\Query\Selection\SelectEntity;
19
use Happyr\DoctrineSpecification\Query\Selection\Selection;
20
use PhpSpec\ObjectBehavior;
21
22
/**
23
 * @mixin SelectEntity
24
 */
25
final class SelectEntitySpec extends ObjectBehavior
26
{
27
    private $dqlAlias = 'u';
28
29
    public function let(): void
30
    {
31
        $this->beConstructedWith($this->dqlAlias);
32
    }
33
34
    public function it_is_a_select_entity(): void
35
    {
36
        $this->shouldBeAnInstanceOf(SelectEntity::class);
37
    }
38
39
    public function it_is_a_selection(): void
40
    {
41
        $this->shouldBeAnInstanceOf(Selection::class);
42
    }
43
44
    public function it_is_transformable(QueryBuilder $qb): void
45
    {
46
        $qb->getDQLPart('join')->willReturn([]);
47
        $qb->getAllAliases()->willReturn([]);
48
        $qb->join(sprintf('a.%s', $this->dqlAlias), $this->dqlAlias)->willReturn($qb);
49
50
        $this->transform($qb, 'a')->shouldReturn($this->dqlAlias);
51
    }
52
53
    public function it_is_transformable_in_context(QueryBuilder $qb): void
54
    {
55
        $context = 'foo.bar';
56
57
        $this->beConstructedWith(sprintf('%s.%s', $context, $this->dqlAlias));
58
59
        $qb->getDQLPart('join')->willReturn([]);
60
        $qb->getAllAliases()->willReturn([]);
61
        $qb->join('a.foo', 'foo')->willReturn($qb);
62
        $qb->join('foo.bar', 'bar')->willReturn($qb);
63
        $qb->join(sprintf('bar.%s', $this->dqlAlias), $this->dqlAlias)->willReturn($qb);
64
65
        $this->transform($qb, 'a')->shouldReturn($this->dqlAlias);
66
    }
67
}
68