ApplicationProviderTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 5
dl 0
loc 67
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testRegister() 0 50 3
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace BaleenTest\Cli\Provider;
21
22
use Baleen\Cli\Application;
23
use Baleen\Cli\CommandBus\AbstractMessage;
24
use Baleen\Cli\CommandBus\Util\ComparatorAwareInterface;
25
use Baleen\Cli\CommandBus\Util\ConfigStorageAwareInterface;
26
use Baleen\Cli\CommandBus\Util\RepositoryAwareInterface;
27
use Baleen\Cli\CommandBus\Util\StorageAwareInterface;
28
use Baleen\Cli\CommandBus\Util\TimelineAwareInterface;
29
use Baleen\Cli\Provider\Services;
30
use Mockery as m;
31
use Symfony\Component\Console\Helper\HelperSet;
32
use Symfony\Component\EventDispatcher\EventDispatcher;
33
34
/**
35
 * Class ApplicationProviderTest
36
 * @author Gabriel Somoza <[email protected]>
37
 */
38
class ApplicationProviderTest extends ServiceProviderTestCase
39
{
40
    /**
41
     * setUp
42
     */
43
    public function setUp()
44
    {
45
        parent::setUp();
46
        $this->setInstance(m::mock(\Baleen\Cli\Provider\ApplicationProvider::class)->makePartial());
47
    }
48
49
    /**
50
     * testRegister
51
     * @dataProvider trueFalseProvider
52
     * @param $isAppRegistered
53
     */
54
    public function testRegister($isAppRegistered)
55
    {
56
        $inflectors = [
57
            RepositoryAwareInterface::class => [
58
                'setRepository' => [Services::REPOSITORY],
59
                'setFilesystem' => [Services::REPOSITORY_FILESYSTEM],
60
            ],
61
            StorageAwareInterface::class => [
62
                'setStorage' => [Services::STORAGE],
63
            ],
64
            TimelineAwareInterface::class => [
65
                'setTimeline' => [Services::TIMELINE],
66
            ],
67
            ComparatorAwareInterface::class => [
68
                'setComparator' => [Services::COMPARATOR],
69
            ],
70
            ConfigStorageAwareInterface::class => [
71
                'setConfigStorage' => [Services::CONFIG_STORAGE],
72
            ],
73
            AbstractMessage::class => [
74
                'setConfig' => [Services::CONFIG],
75
            ]
76
        ];
77
        foreach ($inflectors as $name => $withMethods) {
78
            $this->assertRegistersInflector($name, $withMethods);
79
        }
80
81
        $this->container->shouldReceive('isRegistered')
82
            ->with(Services::APPLICATION)
83
            ->once()
84
            ->andReturn($isAppRegistered);
85
86
        if (!$isAppRegistered) {
87
            $this->assertSingletonProvided(
88
                Services::APPLICATION,
89
                $this->assertCallbackInstanceOf(Application::class, [[], new HelperSet()]),
90
                'string'
91
            )->shouldReceive('withArguments')
92
                ->with([Services::COMMANDS, Services::HELPERSET, Services::APPLICATION_DISPATCHER])->once();
93
        }
94
95
        $this->assertSingletonProvided(
96
            Services::APPLICATION_DISPATCHER,
97
            $this->assertCallbackInstanceOf(EventDispatcher::class),
98
            'string'
99
        );
100
101
102
        $this->getInstance()->register();
103
    }
104
}
105