|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\GridBundle\Doctrine\ORM; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
17
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
18
|
|
|
use Doctrine\ORM\EntityRepository; |
|
19
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
21
|
|
|
use Sylius\Bundle\GridBundle\Doctrine\ORM\DataSource; |
|
22
|
|
|
use Sylius\Component\Grid\Data\DriverInterface; |
|
23
|
|
|
use Sylius\Component\Grid\Parameters; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
final class DriverSpec extends ObjectBehavior |
|
29
|
|
|
{ |
|
30
|
|
|
function let(ManagerRegistry $managerRegistry): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->beConstructedWith($managerRegistry); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_implements_grid_driver(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->shouldImplement(DriverInterface::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_throws_exception_if_class_is_undefined(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this |
|
43
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
|
44
|
|
|
->during('getDataSource', [[], new Parameters()]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function it_creates_data_source_via_doctrine_orm_query_builder( |
|
48
|
|
|
ManagerRegistry $managerRegistry, |
|
49
|
|
|
EntityManagerInterface $entityManager, |
|
50
|
|
|
EntityRepository $entityRepository, |
|
51
|
|
|
QueryBuilder $queryBuilder |
|
52
|
|
|
): void { |
|
53
|
|
|
$managerRegistry->getManagerForClass('App:Book')->willReturn($entityManager); |
|
54
|
|
|
$entityManager->getRepository('App:Book')->willReturn($entityRepository); |
|
55
|
|
|
$entityRepository->createQueryBuilder('o')->willReturn($queryBuilder); |
|
56
|
|
|
|
|
57
|
|
|
$this->getDataSource(['class' => 'App:Book'], new Parameters())->shouldHaveType(DataSource::class); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|