dataResolveEntryNameByContext()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 8.8571
cc 1
eloc 23
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\ResolverByClassName;
14
15
/**
16
 * Class ResolverByClassNameFunctionalTest
17
 *
18
 * @package Nnx\EntryNameResolver\PhpUnit\Test
19
 */
20
class ResolverByClassNameFunctionalTest extends AbstractHttpControllerTestCase
21
{
22
23
    /**
24
     * Данные для тестирования резолвинга на основе конфигов
25
     *
26
     * @return array
27
     */
28
    public function dataResolveEntryNameByContext()
29
    {
30
        return [
31
            [
32
                CustomService\Service\TestComponentInterface::class,
33
                CustomService\Module3\Module::class,
34
                null
35
            ],
36
            [
37
                CustomService\Service\ComponentInterface::class,
38
                \stdClass::class,
39
                CustomService\Service\Component::class
40
            ],
41
            [
42
                \stdClass::class,
43
                \stdClass::class,
44
                null
45
            ],
46
            [
47
                \stdClass::class,
48
                null,
49
                \stdClass::class
50
            ],
51
            [
52
                'notExistsClassName',
53
                null,
54
                null
55
            ],
56
            [
57
                CustomService\Service\ComponentInterface::class,
58
                CustomService\Module3\Module::class,
59
                CustomService\Module3\Component::class
60
            ],
61
            [
62
                CustomService\Service\ComponentInterface::class,
63
                new CustomService\Module3\Module(),
64
                CustomService\Module3\Component::class
65
            ]
66
        ];
67
    }
68
69
70
    /**
71
     * Тестирование резолвинга на основе конфига
72
     *
73
     * @dataProvider dataResolveEntryNameByContext
74
     *
75
     * @param $entryName
76
     * @param $context
77
     * @param $resolvedEntryName
78
     *
79
     * @throws \Zend\Stdlib\Exception\LogicException
80
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
81
     * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException
82
     */
83
    public function testResolveEntryNameByContext($entryName, $context, $resolvedEntryName)
84
    {
85
        /** @noinspection PhpIncludeInspection */
86
        $this->setApplicationConfig(
87
            include TestPaths::getPathToContextResolverAppConfig()
88
        );
89
90
91
        /** @var EntryNameResolverManager $entryNameResolverManager */
92
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
93
94
        /** @var ResolverByClassName $resolverByClassName */
95
        $resolverByClassName = $entryNameResolverManager->get(ResolverByClassName::class);
96
97
        $actualResolvedEntryName = $resolverByClassName->resolveEntryNameByContext($entryName, $context);
98
99
        static::assertEquals($resolvedEntryName, $actualResolvedEntryName);
100
    }
101
102
103
    /**
104
     * Тестирование резолвинга на основе конфига
105
     *
106
     * @expectedExceptionMessage Context of type boolean is invalid; Context not string.
107
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidContextException
108
     *
109
     * @throws \Zend\Stdlib\Exception\LogicException
110
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
111
     * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException
112
     */
113 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...
114
    {
115
        /** @noinspection PhpIncludeInspection */
116
        $this->setApplicationConfig(
117
            include TestPaths::getPathToContextResolverAppConfig()
118
        );
119
120
121
        /** @var EntryNameResolverManager $entryNameResolverManager */
122
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
123
124
        /** @var ResolverByClassName $resolverByClassName */
125
        $resolverByClassName = $entryNameResolverManager->get(ResolverByClassName::class);
126
127
        $resolverByClassName->resolveEntryNameByContext(\stdClass::class, false);
128
    }
129
130
131
    /**
132
     * Тестирование резолвинга на основе конфига
133
     *
134
     * @throws \Zend\Stdlib\Exception\LogicException
135
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
136
     * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException
137
     * @throws \PHPUnit_Framework_AssertionFailedError
138
     */
139
    public function testSetterGetterEntryBodyNamePattern()
140
    {
141
        /** @noinspection PhpIncludeInspection */
142
        $this->setApplicationConfig(
143
            include TestPaths::getPathToContextResolverAppConfig()
144
        );
145
146
147
        /** @var EntryNameResolverManager $entryNameResolverManager */
148
        $entryNameResolverManager = $this->getApplicationServiceLocator()->get(EntryNameResolverManagerInterface::class);
149
150
        /** @var ResolverByClassName $resolverByClassName */
151
        $resolverByClassName = $entryNameResolverManager->get(ResolverByClassName::class);
152
153
        $expectedPattern = 'testPattern';
154
        $valid = $resolverByClassName === $resolverByClassName->setEntryBodyNamePattern($expectedPattern);
155
        static::assertTrue($valid);
156
    }
157
}
158