Completed
Push — master ( 843e94...46dd70 )
by Андрей
6s
created

dataResolveEntryNameByContext()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/entry-name-resolver
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\EntryNameResolver\PhpUnit\Test;
7
8
use Nnx\EntryNameResolver\EntryNameResolverManager;
9
use Nnx\EntryNameResolver\EntryNameResolverManagerInterface;
10
use Nnx\EntryNameResolver\PhpUnit\TestData\TestPaths;
11
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
12
use Nnx\EntryNameResolver\PhpUnit\TestData\ContextResolver\Custom\Service as CustomService;
13
use Nnx\EntryNameResolver\ResolverByModuleContextMap;
14
use Nnx\EntryNameResolver\Exception\RuntimeException;
15
use Nnx\EntryNameResolver\PhpUnit\TestData\ContextResolver\Custom\Service\Module1\InvalidResolverByModuleContextMap;
16
17
18
/**
19
 * Class ResolverByModuleContextMapFunctionalTest
20
 *
21
 * @package Nnx\EntryNameResolver\PhpUnit\Test
22
 */
23
class ResolverByModuleContextMapFunctionalTest extends AbstractHttpControllerTestCase
24
{
25
26
    /**
27
     * Данные для тестирования резолвинга на основе конфигов
28
     *
29
     * @return array
30
     */
31
    public function dataResolveEntryNameByContext()
32
    {
33
        return [
34
            [
35
                CustomService\Service\CustomServiceComponent::class,
36
                [
37
                    CustomService\Service\CustomServiceComponent::class => [
38
                        CustomService\Module1\Module::MODULE_NAME => CustomService\Module1\CustomServiceComponentModule1::class,
39
                        CustomService\Module2\Module::MODULE_NAME => CustomService\Module2\CustomServiceComponentModule2::class,
40
                        CustomService\Module3\Module::MODULE_NAME => CustomService\Module3\CustomServiceComponentModule3::class
41
                    ]
42
                ],
43
                CustomService\Module3\Module::class,
44
                CustomService\Module3\CustomServiceComponentModule3::class
45
            ],
46
            [
47
                CustomService\Service\CustomServiceComponent::class,
48
                [
49
                    CustomService\Service\CustomServiceComponent::class => [
50
                        CustomService\Module1\Module::MODULE_NAME => CustomService\Module1\CustomServiceComponentModule1::class,
51
                        CustomService\Module2\Module::MODULE_NAME => CustomService\Module2\CustomServiceComponentModule2::class,
52
                        CustomService\Module3\Module::MODULE_NAME => CustomService\Module3\CustomServiceComponentModule3::class
53
                    ]
54
                ],
55
                new CustomService\Module3\Module(),
56
                CustomService\Module3\CustomServiceComponentModule3::class
57
            ]
58
        ];
59
    }
60
61
62
    /**
63
     * Тестирование резолвинга на основе конфига
64
     *
65
     * @dataProvider dataResolveEntryNameByContext
66
     *
67
     * @param       $entryName
68
     * @param array $map
69
     * @param       $context
70
     *
71
     * @param       $resolvedEntryName
72
     *
73
     * @throws \Zend\Stdlib\Exception\LogicException
74
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
75
     */
76
    public function testResolveEntryNameByContext($entryName, array $map, $context, $resolvedEntryName)
77
    {
78
        /** @noinspection PhpIncludeInspection */
79
        $this->setApplicationConfig(
80
            include TestPaths::getPathToContextResolverAppConfig()
81
        );
82
83
84
        /** @var EntryNameResolverManager $entryNameResolverManager */
85
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
86
87
        /** @var ResolverByModuleContextMap $resolverByModuleContextMap */
88
        $resolverByModuleContextMap = $entryNameResolverManager->get(ResolverByModuleContextMap::class, [
89
            'contextMap' => $map
90
        ]);
91
92
        $actualResolvedEntryName = $resolverByModuleContextMap->resolveEntryNameByContext($entryName, $context);
93
94
        static::assertEquals($resolvedEntryName, $actualResolvedEntryName);
95
    }
96
97
98
    /**
99
     * Проверка ситуации когда передан не корректный контекст
100
     *
101
     * @expectedExceptionMessage Context of type boolean is invalid; Context not string.
102
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidContextException
103
     *
104
     * @throws \Zend\Stdlib\Exception\LogicException
105
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
106
     */
107 View Code Duplication
    public function testResolveEntryNameByInvalidContext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109
        /** @noinspection PhpIncludeInspection */
110
        $this->setApplicationConfig(
111
            include TestPaths::getPathToContextResolverAppConfig()
112
        );
113
114
115
        /** @var EntryNameResolverManager $entryNameResolverManager */
116
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
117
118
        /** @var ResolverByModuleContextMap $resolverByModuleContextMap */
119
        $resolverByModuleContextMap = $entryNameResolverManager->get(ResolverByModuleContextMap::class);
120
121
        $resolverByModuleContextMap->resolveEntryNameByContext('test', false);
122
    }
123
124
    /**
125
     * Проверка ситуации когда,
126
     *
127
     *
128
     * @throws \Zend\Stdlib\Exception\LogicException
129
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
130
     * @throws \Interop\Container\Exception\NotFoundException
131
     * @throws \Interop\Container\Exception\ContainerException
132
     */
133 View Code Duplication
    public function testInvalidEntryNameResolverChainClassName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        /** @noinspection PhpIncludeInspection */
136
        $this->setApplicationConfig(
137
            include TestPaths::getPathToContextResolverAppConfig()
138
        );
139
140
        /** @var EntryNameResolverManagerInterface $entryNameResolverManager */
141
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
142
143
        $e = null;
144
        try {
145
            $entryNameResolverManager->get(ResolverByModuleContextMap::class, [
146
                'className' => InvalidResolverByModuleContextMap::class
147
            ]);
148
        } catch (\Exception $ex) {
149
            $e = $ex;
150
        }
151
152
        static::assertInstanceOf(\Exception::class, $e);
153
        $prevException = $e->getPrevious();
154
        static::assertInstanceOf(RuntimeException::class, $prevException);
155
        static::assertEquals('ResolverByModuleContextMap not implements: Nnx\EntryNameResolver\ResolverByModuleContextMap', $prevException->getMessage());
156
    }
157
}
158