Completed
Push — master ( 4edf95...ab1be0 )
by Андрей
02:23
created

testResolveEntryNameByContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 8

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 1
eloc 8
nc 1
nop 4
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
15
/**
16
 * Class ResolverByModuleContextMapFunctionalTest
17
 *
18
 * @package Nnx\EntryNameResolver\PhpUnit\Test
19
 */
20
class ResolverByModuleContextMapFunctionalTest extends AbstractHttpControllerTestCase
21
{
22
23
    /**
24
     * Данные для тестирования резолвинга на основе конфигов
25
     *
26
     * @return array
27
     */
28
    public function dataResolveEntryNameByContext()
29
    {
30
        return [
31
            [
32
                CustomService\Service\CustomServiceComponent::class,
33
                [
34
                    CustomService\Service\CustomServiceComponent::class => [
35
                        CustomService\Module1\Module::MODULE_NAME => CustomService\Module1\CustomServiceComponentModule1::class,
36
                        CustomService\Module2\Module::MODULE_NAME => CustomService\Module2\CustomServiceComponentModule2::class,
37
                        CustomService\Module3\Module::MODULE_NAME => CustomService\Module3\CustomServiceComponentModule3::class
38
                    ]
39
                ],
40
                CustomService\Module3\Module::class,
41
                CustomService\Module3\CustomServiceComponentModule3::class
42
            ],
43
            [
44
                CustomService\Service\CustomServiceComponent::class,
45
                [
46
                    CustomService\Service\CustomServiceComponent::class => [
47
                        CustomService\Module1\Module::MODULE_NAME => CustomService\Module1\CustomServiceComponentModule1::class,
48
                        CustomService\Module2\Module::MODULE_NAME => CustomService\Module2\CustomServiceComponentModule2::class,
49
                        CustomService\Module3\Module::MODULE_NAME => CustomService\Module3\CustomServiceComponentModule3::class
50
                    ]
51
                ],
52
                new CustomService\Module3\Module(),
53
                CustomService\Module3\CustomServiceComponentModule3::class
54
            ]
55
        ];
56
    }
57
58
59
    /**
60
     * Тестирование резолвинга на основе конфига
61
     *
62
     * @dataProvider dataResolveEntryNameByContext
63
     *
64
     * @param       $entryName
65
     * @param array $map
66
     * @param       $context
67
     *
68
     * @param       $resolvedEntryName
69
     *
70
     * @throws \Zend\Stdlib\Exception\LogicException
71
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
72
     */
73 View Code Duplication
    public function testResolveEntryNameByContext($entryName, array $map, $context, $resolvedEntryName)
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...
74
    {
75
        /** @noinspection PhpIncludeInspection */
76
        $this->setApplicationConfig(
77
            include TestPaths::getPathToContextResolverAppConfig()
78
        );
79
80
81
        /** @var EntryNameResolverManager $entryNameResolverManager */
82
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
83
84
        /** @var ResolverByModuleContextMap $resolverByModuleContextMap */
85
        $resolverByModuleContextMap = $entryNameResolverManager->get(ResolverByModuleContextMap::class);
86
87
88
        $resolverByModuleContextMap->setContextMap($map);
89
90
        $actualResolvedEntryName = $resolverByModuleContextMap->resolveEntryNameByContext($entryName, $context);
91
92
        static::assertEquals($resolvedEntryName, $actualResolvedEntryName);
93
    }
94
95
96
    /**
97
     * Проверка ситуации когда передан не корректный контекст
98
     *
99
     * @expectedExceptionMessage Context of type boolean is invalid; Context not string.
100
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidContextException
101
     *
102
     * @throws \Zend\Stdlib\Exception\LogicException
103
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
104
     */
105 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...
106
    {
107
        /** @noinspection PhpIncludeInspection */
108
        $this->setApplicationConfig(
109
            include TestPaths::getPathToContextResolverAppConfig()
110
        );
111
112
113
        /** @var EntryNameResolverManager $entryNameResolverManager */
114
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
115
116
        /** @var ResolverByModuleContextMap $resolverByModuleContextMap */
117
        $resolverByModuleContextMap = $entryNameResolverManager->get(ResolverByModuleContextMap::class);
118
119
        $resolverByModuleContextMap->resolveEntryNameByContext('test', false);
120
    }
121
}
122