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
|
|
|
|