Completed
Branch master (0b86d9)
by Léo
02:17
created

testFailsWhenServiceIsAbstract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\Leogout\Bundle\SeoBundle\DependencyInjection\Compiler;
4
5
use Leogout\Bundle\SeoBundle\DependencyInjection\Compiler\SeoGeneratorPass;
6
use Leogout\Bundle\SeoBundle\Tests\TestCase;
7
8
/**
9
 * Description of SeoGeneratorPassTest.
10
 *
11
 * @author: leogout
12
 */
13
class SeoGeneratorPassTest extends TestCase
14
{
15
    private $containerBuilder;
16
    private $definition;
17
    private $builderDefinition;
18
19
    /**
20
     * @var SeoGeneratorPass
21
     */
22
    private $pass;
23
24
    protected function setUp()
25
    {
26
        $this->containerBuilder = $this->prophesize('Symfony\Component\DependencyInjection\ContainerBuilder');
27
        $this->definition = $this->prophesize('Symfony\Component\DependencyInjection\Definition');
28
        $this->builderDefinition = $this->prophesize('Symfony\Component\DependencyInjection\Definition');
29
        $this->pass = new SeoGeneratorPass();
30
        $this->containerBuilder->getDefinition('leogout_seo.provider.generator')->willReturn($this->definition);
31
        $this->containerBuilder->getDefinition('id')->willReturn($this->builderDefinition);
32
        $this->builderDefinition->isPublic()->willReturn(true);
33
        $this->builderDefinition->isAbstract()->willReturn(false);
34
    }
35
36
    /**
37
     * @expectedException \InvalidArgumentException
38
     * @expectedExceptionMessage Seo generator services cannot be abstract but "id" is.
39
     */
40
    public function testFailsWhenServiceIsAbstract()
41
    {
42
        $this->builderDefinition->isAbstract()->willReturn(true);
43
        $this->containerBuilder->findTaggedServiceIds('leogout_seo.generator')->willReturn(['id' => [['alias' => 'foo']]]);
44
        $this->pass->process($this->containerBuilder->reveal());
45
    }
46
47
    /**
48
     * @expectedException \InvalidArgumentException
49
     * @expectedExceptionMessage Seo generator services must be public, but "id" is not.
50
     */
51
    public function testFailsWhenServiceIsPrivate()
52
    {
53
        $this->builderDefinition->isPublic()->willReturn(false);
54
        $this->containerBuilder->findTaggedServiceIds('leogout_seo.generator')->willReturn(['id' => [['alias' => 'foo']]]);
55
        $this->pass->process($this->containerBuilder->reveal());
56
    }
57
58
    /**
59
     * @expectedException \InvalidArgumentException
60
     * @expectedExceptionMessage Tag "leogout_seo.generator" requires an "alias" field in "id" definition.
61
     */
62
    public function testFailsWhenAliasIsMissing()
63
    {
64
        $this->containerBuilder->findTaggedServiceIds('leogout_seo.generator')->willReturn(['id' => [['alias' => '']]]);
65
        $this->pass->process($this->containerBuilder->reveal());
66
    }
67
}
68