test_getConfiguredProviders_fromConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 14
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Nip\Container\Tests\ServiceProviders;
4
5
use Mockery\Mock;
6
use Nip\Config\Config;
7
use Nip\Container\Container;
8
use Nip\Container\Tests\AbstractTest;
9
use Nip\Container\Tests\Fixtures\ServiceProviderAwareObject;
10
11
/**
12
 * Class ServiceProviderAwareTraitTest
13
 * @package Nip\Container\Tests\ServiceProvider
14
 */
15
class ServiceProviderAwareTraitTest extends AbstractTest
16
{
17
    public function test_getConfiguredProviders_noConfig()
18
    {
19
        $object = $this->generateMockedObject();
20
        $object->shouldReceive('getGenericProviders')->once()->andReturn([]);
21
22
        $configured = $object->getConfiguredProviders();
23
        self::assertIsArray($configured);
24
    }
25
26
    public function test_getConfiguredProviders_fromConfig()
27
    {
28
        $container = new Container();
29
        $config = new Config(['app' => ['providers' => ['test' => 'name']]]);
30
        $container->set('config', $config);
31
        Container::setInstance($container);
32
        \Nip\Container\Utility\Container::container(true);
33
34
        $object = $this->generateMockedObject();
35
        $object->shouldReceive('getGenericProviders')->once()->andReturn([]);
36
37
        $configured = $object->getConfiguredProviders();
38
        self::assertIsArray($configured);
39
        self::assertArrayHasKey('test', $configured);
40
    }
41
42
    /**
43
     * @return Mock|ServiceProviderAwareObject
44
     */
45
    protected function generateMockedObject()
46
    {
47
        $object = \Mockery::mock(ServiceProviderAwareObject::class)
48
            ->makePartial()
49
            ->shouldAllowMockingProtectedMethods();
50
        return $object;
51
    }
52
}
53