testSetterGetterFlagCheckAbstractFactories()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/container
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Container\PhpUnit\Test;
7
8
use Nnx\Container\Container;
9
use Nnx\Container\PhpUnit\TestData\TestPaths;
10
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
11
use Nnx\Container\ContainerInterface;
12
use Nnx\Container\PhpUnit\TestData\ContextResolver\Custom\Service as ServiceApp;
13
14
/**
15
 * Class ContainerFunctionalTest
16
 *
17
 * @package Nnx\Container\PhpUnit\Test
18
 */
19
class ContainerFunctionalTest extends AbstractHttpControllerTestCase
20
{
21
22
    /**
23
     * @inheritdoc
24
     *
25
     * @throws \Zend\Stdlib\Exception\LogicException
26
     */
27
    protected function setUp()
28
    {
29
        /** @noinspection PhpIncludeInspection */
30
        $this->setApplicationConfig(
31
            include TestPaths::getPathToContextResolverAppConfig()
32
        );
33
34
        parent::setUp();
35
    }
36
37
38
    /**
39
     * Тестирование получения службы по контексту
40
     *
41
     * @return array
42
     */
43
    public function dataTestGetEntryByContext()
44
    {
45
        return [
46
            ['testResolveServiceByConfig', ServiceApp\Module3\Module::class, ServiceApp\Module3\ResolvedServiceByConfigFromModule3Context::class],
47
            ['testResolveServiceByConfig', ServiceApp\Module2\Module::class, ServiceApp\Module2\ResolvedServiceByConfigFromModule2Context::class],
48
            [ServiceApp\Module3\Service\ComponentInterface::class, ServiceApp\Module3\Module::class, ServiceApp\Module3\ResolvedServiceByConfigFromModule3Context::class],
49
            [ServiceApp\Module3\Service\ComponentInterface::class, ServiceApp\Module2\Module::class, ServiceApp\Module2\Service\Component::class]
50
        ];
51
    }
52
53
54
    /**
55
     * Проверка ситуации когда пытаемся получить сервис, который:
56
     * 1) Не может быть разрезолвен в другой, в зависимости от контекста
57
     * 2) Не зарегестрирован в ServiceLocator приложения
58
     *
59
     *
60
     * @expectedException \Zend\ServiceManager\Exception\ServiceNotFoundException
61
     * @expectedExceptionMessage Nnx\Container\Container::get was unable to fetch or create an instance for
62
     *
63
     *
64
     * @return void
65
     *
66
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
67
     * @throws \Zend\Stdlib\Exception\LogicException
68
     */
69
    public function testLoadModule()
70
    {
71
        /** @var ContainerInterface $container */
72
        $container = $this->getApplicationServiceLocator()->get(ContainerInterface::class);
73
74
        $entryName = 'UnknownService';
75
        $container->get($entryName);
76
    }
77
78
79
    /**
80
     * Тестирование получени службы, в зависимости от контекста
81
     *
82
     * @dataProvider dataTestGetEntryByContext
83
     *
84
     * @param $entryName
85
     * @param $context
86
     * @param $expectedEntryClassName
87
     *
88
     * @throws \Zend\Stdlib\Exception\LogicException
89
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
90
     */
91
    public function testGetEntryByContext($entryName, $context, $expectedEntryClassName)
92
    {
93
        /** @var ContainerInterface $container */
94
        $container = $this->getApplicationServiceLocator()->get(ContainerInterface::class);
95
96
        static::assertInstanceOf($expectedEntryClassName, $container->get($entryName, [], null, $context));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
        static::assertInstanceOf($expectedEntryClassName, $container->getByContext($entryName, [], $context));
98
        static::assertTrue($container->has($entryName, true, true, $context));
99
        static::assertTrue($container->hasByContext($entryName, $context));
100
    }
101
102
    /**
103
     *  Проверка getter/setter для свойства flagUsePeeringServiceManagers
104
     *
105
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
106
     */
107
    public function testSetterGetterFlagUsePeeringServiceManagers()
108
    {
109
        /** @var Container $container */
110
        $container = $this->getApplicationServiceLocator()->get(ContainerInterface::class);
111
112
        static::assertEquals($container, $container->setFlagUsePeeringServiceManagers(true));
113
        static::assertTrue($container->getFlagUsePeeringServiceManagers());
114
    }
115
116
117
    /**
118
     *  Проверка getter/setter для свойства flagCheckAbstractFactories
119
     *
120
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
121
     */
122
    public function testSetterGetterFlagCheckAbstractFactories()
123
    {
124
        /** @var Container $container */
125
        $container = $this->getApplicationServiceLocator()->get(ContainerInterface::class);
126
127
        static::assertEquals($container, $container->setFlagCheckAbstractFactories(false));
128
        static::assertFalse($container->getFlagCheckAbstractFactories());
129
    }
130
}
131