doRunShouldInjectTheContainerOnContainerAwareCommands()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of LuisMulinari\Consoleful
4
 *
5
 * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
6
 */
7
8
namespace LuisMulinari\Consoleful;
9
10
use Lcobucci\DependencyInjection\ContainerBuilder;
11
use Lcobucci\DependencyInjection\ContainerConfig;
12
use Lcobucci\DependencyInjection\Builders\DelegatingBuilder;
13
use LuisMulinari\Consoleful\fixtures\CommandTest;
14
use LuisMulinari\Consoleful\fixtures\ContainerAwareCommandTest;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
19
/**
20
 * Class ApplicationTest
21
 *
22
 * @author Luis Henrique Mulinari <[email protected]>
23
 */
24
class ApplicationTest extends \PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var ContainerBuilder
28
     */
29
    protected $builder;
30
31
    /**
32
     * @var ContainerConfig
33
     */
34
    protected $config;
35
36
    protected function setUp()
37
    {
38
        $this->config = $this->getMock(ContainerConfig::class, [], [], '', false);
39
        $this->builder = $this->getMockForAbstractClass(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac... array('getContainer')) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Lcobucci\Dependen...ction\ContainerBuilder> of property $builder.

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...
40
            ContainerBuilder::class,
41
            [],
42
            '',
43
            true,
44
            true,
45
            true,
46
            ['getContainer']
47
        );
48
    }
49
50
    /**
51
     * @test
52
     *
53
     * @covers LuisMulinari\Consoleful\Application::__construct
54
     * @covers Symfony\Component\Console\Application::__construct
55
     */
56
    public function constructShouldConfigureTheAttributes()
57
    {
58
        $application = new Application('name', 'version', $this->config, $this->builder);
59
60
        $this->assertAttributeEquals('name', 'name', $application);
61
        $this->assertAttributeEquals('version', 'version', $application);
62
        $this->assertAttributeSame($this->config, 'containerConfig', $application);
63
        $this->assertAttributeSame($this->builder, 'builder', $application);
64
    }
65
66
    /**
67
     * @test
68
     *
69
     * @covers LuisMulinari\Consoleful\Application::__construct
70
     * @covers Symfony\Component\Console\Application::__construct
71
     */
72
    public function constructShouldCreateBuilderWhenNotInformed()
73
    {
74
        $application = new Application('name', 'version', $this->config);
75
76
        $this->assertAttributeInstanceOf(DelegatingBuilder::class, 'builder', $application);
77
    }
78
79
    /**
80
     * @test
81
     *
82
     * @covers LuisMulinari\Consoleful\Application::__construct
83
     * @covers LuisMulinari\Consoleful\Application::doRun
84
     * @covers LuisMulinari\Consoleful\Application::injectContainer
85
     * @covers Symfony\Component\Console\Application::__construct
86
     * @covers Symfony\Component\Console\Application::doRun
87
     * @covers Lcobucci\DependencyInjection\ContainerInjector::setContainer
88
     * @covers Lcobucci\DependencyInjection\ContainerInjector::getContainer
89
     */
90
    public function doRunShouldNotBuildTheContainerWhenNoConfigurationWasUsed()
91
    {
92
        $input = $this->getMock(InputInterface::class);
93
        $output = $this->getMock(OutputInterface::class);
94
95
        $this->builder->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Lcobucci\Dependen...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
                      ->method('getContainer');
97
98
        $application = new Application('name', 'version', null, $this->builder);
99
        $application->doRun($input, $output);
100
101
        $this->assertAttributeEquals(null, 'container', $application);
102
    }
103
104
    /**
105
     * @test
106
     *
107
     * @covers LuisMulinari\Consoleful\Application::__construct
108
     * @covers LuisMulinari\Consoleful\Application::doRun
109
     * @covers LuisMulinari\Consoleful\Application::injectContainer
110
     * @covers Symfony\Component\Console\Application::__construct
111
     * @covers Symfony\Component\Console\Application::doRun
112
     * @covers Lcobucci\DependencyInjection\ContainerInjector::setContainer
113
     * @covers Lcobucci\DependencyInjection\ContainerInjector::getContainer
114
     */
115
    public function doRunShouldBuildTheContainerIfItWasnConfiguredYet()
116
    {
117
        $input = $this->getMock(InputInterface::class);
118
        $output = $this->getMock(OutputInterface::class);
119
        $container = $this->getMock(ContainerInterface::class);
120
121
        $this->builder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Lcobucci\Dependen...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122
                      ->method('getContainer')
123
                      ->with($this->config)
124
                      ->willReturn($container);
125
126
        $application = new Application('name', 'version', $this->config, $this->builder);
127
        $application->doRun($input, $output);
128
129
        $this->assertAttributeSame($container, 'container', $application);
130
    }
131
132
    /**
133
     * @test
134
     *
135
     * @covers LuisMulinari\Consoleful\Application::__construct
136
     * @covers LuisMulinari\Consoleful\Application::doRun
137
     * @covers LuisMulinari\Consoleful\Application::injectContainer
138
     * @covers Symfony\Component\Console\Application::__construct
139
     * @covers Symfony\Component\Console\Application::add
140
     * @covers Symfony\Component\Console\Application::doRun
141
     * @covers Lcobucci\DependencyInjection\ContainerInjector::setContainer
142
     * @covers Lcobucci\DependencyInjection\ContainerInjector::getContainer
143
     */
144
    public function doRunShouldInjectTheContainerOnContainerAwareCommands()
145
    {
146
        $input = $this->getMock(InputInterface::class);
147
        $output = $this->getMock(OutputInterface::class);
148
        $container = $this->getMock(ContainerInterface::class);
149
150
        $this->builder->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Lcobucci\Dependen...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
151
                      ->method('getContainer');
152
153
        $command = new CommandTest();
154
        $command2 = new ContainerAwareCommandTest();
155
156
        $application = new Application('name', 'version', $this->config, $this->builder);
157
        $application->add($command);
158
        $application->add($command2);
159
        $application->setContainer($container);
160
        $application->doRun($input, $output);
161
162
        $this->assertAttributeSame($container, 'container', $command2);
163
    }
164
}
165