Completed
Push — develop ( dcf765...a9e6df )
by Léo
11s
created

SeoGeneratorPassTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testFailsWhenServiceIsAbstract() 0 6 1
A testFailsWhenServiceIsPrivate() 0 6 1
A testFailsWhenAliasIsMissing() 0 5 1
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
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Description of SeoGeneratorPassTest.
11
 *
12
 * @author: leogout
13
 */
14
class SeoGeneratorPassTest extends TestCase
15
{
16
    private $containerBuilder;
17
    private $definition;
18
    private $builderDefinition;
19
20
    /**
21
     * @var MenuBuilderPass
22
     */
23
    private $pass;
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Leogout\Bundle\SeoB...iler\SeoGeneratorPass() of type object<Leogout\Bundle\Se...piler\SeoGeneratorPass> is incompatible with the declared type object<Tests\Leogout\Bun...mpiler\MenuBuilderPass> of property $pass.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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