|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Odiseo\SyliusReportPlugin\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
13
|
|
|
* @author Diego D'amico <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class RegisterDataFetchersPassSpec extends ObjectBehavior |
|
16
|
|
|
{ |
|
17
|
|
|
function it_should_implement_compiler_pass_interface() |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
$this->shouldImplement(CompilerPassInterface::class); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function it_processes_with_given_container(ContainerBuilder $container, Definition $dataFetcherDefinition) |
|
23
|
|
|
{ |
|
24
|
|
|
$container->hasDefinition('odiseo_sylius_report.registry.data_fetcher')->willReturn(true); |
|
25
|
|
|
$container->getDefinition('odiseo_sylius_report.registry.data_fetcher')->willReturn($dataFetcherDefinition); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$dataFetcherServices = [ |
|
28
|
|
|
'odiseo_sylius_report.form.type.data_fetcher.test' => [ |
|
29
|
|
|
['fetcher' => 'test', 'label' => 'Test data fetcher'], |
|
30
|
|
|
], |
|
31
|
|
|
]; |
|
32
|
|
|
$container->findTaggedServiceIds('odiseo_sylius_report.data_fetcher')->willReturn($dataFetcherServices); |
|
33
|
|
|
|
|
34
|
|
|
$dataFetcherDefinition->addMethodCall('register', ['test', new Reference('odiseo_sylius_report.form.type.data_fetcher.test')])->shouldBeCalled(); |
|
|
|
|
|
|
35
|
|
|
$container->setParameter('odiseo_sylius_report.data_fetchers', ['test' => 'Test data fetcher'])->shouldBeCalled(); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->process($container); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_does_not_process_if_container_has_not_proper_definition(ContainerBuilder $container) |
|
41
|
|
|
{ |
|
42
|
|
|
$container->hasDefinition('odiseo_sylius_report.registry.data_fetcher')->willReturn(false); |
|
43
|
|
|
$container->getDefinition('odiseo_sylius_report.registry.data_fetcher')->shouldNotBeCalled(); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$this->process($container); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_throws_exception_if_any_data_fetcher_has_improper_attributes(ContainerBuilder $container, Definition $dataFetcherDefinition) |
|
49
|
|
|
{ |
|
50
|
|
|
$container->hasDefinition('odiseo_sylius_report.registry.data_fetcher')->willReturn(true); |
|
51
|
|
|
$container->getDefinition('odiseo_sylius_report.registry.data_fetcher')->willReturn($dataFetcherDefinition); |
|
52
|
|
|
|
|
53
|
|
|
$dataFetcherServices = [ |
|
54
|
|
|
'odiseo_sylius_report.form.type.data_fetcher.test' => [ |
|
55
|
|
|
['data_fetcher' => 'test'], |
|
56
|
|
|
], |
|
57
|
|
|
]; |
|
58
|
|
|
$container->findTaggedServiceIds('odiseo_sylius_report.data_fetcher')->willReturn($dataFetcherServices); |
|
59
|
|
|
$dataFetcherDefinition->addMethodCall('register', ['test', new Reference('odiseo_sylius_report.form.type.data_fetcher.test')])->shouldNotBeCalled(); |
|
60
|
|
|
|
|
61
|
|
|
$this->shouldThrow(new \InvalidArgumentException('Tagged report data fetchers needs to have `fetcher` and `label` attributes.')) |
|
62
|
|
|
->during('process', [$container]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.