|
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
|
|
|
namespace Sylius\Bundle\CoreBundle\Tests\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
15
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasMethodCallConstraint; |
|
16
|
|
|
use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\SitemapProviderPass; |
|
17
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Builder\SitemapBuilder; |
|
18
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Provider\ProductUrlProvider; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class SitemapProviderPassTest extends AbstractCompilerPassTestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @test |
|
30
|
|
|
*/ |
|
31
|
|
|
public function it_adds_method_call_to_sitemap_builder_if_providers_exist() |
|
32
|
|
|
{ |
|
33
|
|
|
$sitemapBuilderDefinition = new Definition(SitemapBuilder::class); |
|
34
|
|
|
$this->setDefinition('sylius.sitemap_builder', $sitemapBuilderDefinition); |
|
35
|
|
|
|
|
36
|
|
|
$productUrlProviderDefinition = new Definition(ProductUrlProvider::class); |
|
37
|
|
|
$productUrlProviderDefinition->addTag('sylius.sitemap_provider'); |
|
38
|
|
|
$this->setDefinition('sylius.sitemap_provider.product', $productUrlProviderDefinition); |
|
39
|
|
|
|
|
40
|
|
|
$this->compile(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
43
|
|
|
'sylius.sitemap_builder', |
|
44
|
|
|
'addProvider', |
|
45
|
|
|
[ |
|
46
|
|
|
new Reference('sylius.sitemap_provider.product'), |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @test |
|
53
|
|
|
*/ |
|
54
|
|
|
public function it_does_not_add_method_call_if_there_is_no_url_providers() |
|
55
|
|
|
{ |
|
56
|
|
|
$sitemapBuilderDefinition = new Definition(SitemapBuilder::class); |
|
57
|
|
|
$this->setDefinition('sylius.sitemap_builder', $sitemapBuilderDefinition); |
|
58
|
|
|
|
|
59
|
|
|
$this->compile(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertContainerBuilderDoesNotHaveServiceDefinitionWithMethodCall( |
|
62
|
|
|
'sylius.sitemap_builder', |
|
63
|
|
|
'addProvider' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
71
|
|
|
{ |
|
72
|
|
|
$container->addCompilerPass(new SitemapProviderPass()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $serviceId |
|
77
|
|
|
* @param string $method |
|
78
|
|
|
*/ |
|
79
|
|
|
private function assertContainerBuilderDoesNotHaveServiceDefinitionWithMethodCall($serviceId, $method) |
|
80
|
|
|
{ |
|
81
|
|
|
$definition = $this->container->findDefinition($serviceId); |
|
82
|
|
|
|
|
83
|
|
|
self::assertThat( |
|
84
|
|
|
$definition, |
|
85
|
|
|
new \PHPUnit_Framework_Constraint_Not(new DefinitionHasMethodCallConstraint($method)) |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|