Passed
Push — master ( 4826f7...743cc2 )
by Oleg
04:24
created

ConfigTest::testNewConfig()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 76
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 52
nc 2
nop 0
dl 0
loc 76
rs 8.9667
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Config;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use org\bovigo\vfs\vfsStream;
8
use PHPUnit\Framework\TestCase;
9
use Prophecy\Argument;
10
use Prophecy\Prophecy\ObjectProphecy;
11
use SlayerBirden\DFCodeGeneration\PrintFileTrait;
12
13
class ConfigTest extends TestCase
14
{
15
    use PrintFileTrait;
16
    /**
17
     * @var ObjectProphecy
18
     */
19
    private $provider;
20
21
    protected function setUp()
22
    {
23
        $this->provider = $this->prophesize(DataProviderInterface::class);
24
        $this->provider->getRouteFactoryName()->willReturn('Routes');
25
        $this->provider->getInputFilterSpec()->willReturn([
26
            'bar' => [
27
                'required' => true,
28
            ],
29
            'baz' => [
30
                'required' => true,
31
            ],
32
        ]);
33
        $this->provider->getInputFilterName()->willReturn('DummyInputFilter');
34
        $this->provider->getEntitiesSrc()->willReturn('src/Dummy/Entities');
35
        $this->provider->getCurrentConfig()->willReturn([]);
36
        $this->provider->getControllerName(Argument::type('string'))->will(function ($args) {
37
            return ucwords($args[0]) . 'DummyAction';
38
        });
39
        $this->provider->getConfigNameSpace()->willReturn('A\B');
40
    }
41
42
    public function testNewConfig()
43
    {
44
        $configGenerator = new Config($this->provider->reveal());
45
        $value = $configGenerator->generate();
46
47
        $root = vfsStream::setup();
48
        file_put_contents($root->url() . '/dummyProvider.php', $value);
49
        try {
50
            include $root->url() . '/dummyProvider.php';
51
        } catch (\ParseError $exception) {
52
            echo 'File', PHP_EOL, $this->getPrintableFile($value), PHP_EOL;
53
            throw $exception;
54
        }
55
56
        $class = $configGenerator->getClassName();
57
        $config = new $class();
58
59
        $actual = call_user_func($config);
0 ignored issues
show
Bug introduced by
$config of type object is incompatible with the type callable expected by parameter $function of call_user_func(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        $actual = call_user_func(/** @scrutinizer ignore-type */ $config);
Loading history...
60
61
        $expected = [
62
            '\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [
63
                'AddDummyAction' => [
64
                    EntityManagerInterface::class,
65
                    '\\Zend\\Hydrator\\ClassMethods',
66
                    'DummyInputFilter',
67
                    '\\Psr\\Log\\LoggerInterface',
68
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
69
                ],
70
                'UpdateDummyAction' => [
71
                    EntityManagerInterface::class,
72
                    '\\Zend\\Hydrator\\ClassMethods',
73
                    'DummyInputFilter',
74
                    '\\Psr\\Log\\LoggerInterface',
75
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
76
                ],
77
                'GetDummyAction' => [
78
                    EntityManagerInterface::class,
79
                    '\\Psr\\Log\\LoggerInterface',
80
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
81
                ],
82
                'GetsDummyAction' => [
83
                    EntityManagerInterface::class,
84
                    '\\Psr\\Log\\LoggerInterface',
85
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
86
                ],
87
                'DeleteDummyAction' => [
88
                    EntityManagerInterface::class,
89
                    '\\Psr\\Log\\LoggerInterface',
90
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
91
                ],
92
            ],
93
            'dependencies' => [
94
                'delegators' => [
95
                    '\\Zend\\Expressive\\Application' => [
96
                        'Routes',
97
                    ],
98
                ],
99
            ],
100
            'doctrine' => [
101
                'paths' => [
102
                    'src/Dummy/Entities'
103
                ],
104
            ],
105
            'input_filter_specs' => [
106
                'DummyInputFilter' => [
107
                    'bar' => [
108
                        'required' => true,
109
                    ],
110
                    'baz' => [
111
                        'required' => true,
112
                    ],
113
                ],
114
            ],
115
        ];
116
117
        $this->assertEquals($expected, $actual);
118
    }
119
120
    public function testExistingConfig()
121
    {
122
        $this->provider->getCurrentConfig()->willReturn([
123
            '\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [
124
                'AddSuperAction' => [
125
                    EntityManagerInterface::class,
126
                    '\\Zend\\Hydrator\\ClassMethods',
127
                    'SuperInputFilter',
128
                    '\\Psr\\Log\\LoggerInterface',
129
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
130
                ],
131
                'UpdateSuperAction' => [
132
                    EntityManagerInterface::class,
133
                    '\\Zend\\Hydrator\\ClassMethods',
134
                    'SuperInputFilter',
135
                    '\\Psr\\Log\\LoggerInterface',
136
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
137
                ],
138
                'GetSuperAction' => [
139
                    EntityManagerInterface::class,
140
                    '\\Psr\\Log\\LoggerInterface',
141
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
142
                ],
143
                'GetsSuperAction' => [
144
                    EntityManagerInterface::class,
145
                    '\\Psr\\Log\\LoggerInterface',
146
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
147
                ],
148
                'DeleteSuperAction' => [
149
                    EntityManagerInterface::class,
150
                    '\\Psr\\Log\\LoggerInterface',
151
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
152
                ],
153
            ],
154
            'dependencies' => [
155
                'delegators' => [
156
                    '\\Zend\\Expressive\\Application' => [
157
                        'Routes',
158
                    ],
159
                ],
160
            ],
161
            'doctrine' => [
162
                'paths' => [
163
                    'src/Dummy/Entities'
164
                ],
165
            ],
166
            'input_filter_specs' => [
167
                'SuperInputFilter' => [
168
                    'bar' => [
169
                        'required' => true,
170
                    ],
171
                    'baz' => [
172
                        'required' => true,
173
                    ],
174
                ],
175
            ],
176
        ]);
177
        $this->provider->getConfigNameSpace()->willReturn('A\C');
178
179
        $configGenerator = new Config($this->provider->reveal());
180
        $value = $configGenerator->generate();
181
182
        $root = vfsStream::setup();
183
        file_put_contents($root->url() . '/dummyProvider.php', $value);
184
        try {
185
            include $root->url() . '/dummyProvider.php';
186
        } catch (\ParseError $exception) {
187
            echo 'File', PHP_EOL, $this->getPrintableFile($value), PHP_EOL;
188
            throw $exception;
189
        }
190
191
        $class = $configGenerator->getClassName();
192
        $config = new $class();
193
194
        $actual = call_user_func($config);
0 ignored issues
show
Bug introduced by
$config of type object is incompatible with the type callable expected by parameter $function of call_user_func(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

194
        $actual = call_user_func(/** @scrutinizer ignore-type */ $config);
Loading history...
195
196
        $expected = [
197
            '\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [
198
                'AddSuperAction' => [
199
                    EntityManagerInterface::class,
200
                    '\\Zend\\Hydrator\\ClassMethods',
201
                    'SuperInputFilter',
202
                    '\\Psr\\Log\\LoggerInterface',
203
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
204
                ],
205
                'UpdateSuperAction' => [
206
                    EntityManagerInterface::class,
207
                    '\\Zend\\Hydrator\\ClassMethods',
208
                    'SuperInputFilter',
209
                    '\\Psr\\Log\\LoggerInterface',
210
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
211
                ],
212
                'GetSuperAction' => [
213
                    EntityManagerInterface::class,
214
                    '\\Psr\\Log\\LoggerInterface',
215
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
216
                ],
217
                'GetsSuperAction' => [
218
                    EntityManagerInterface::class,
219
                    '\\Psr\\Log\\LoggerInterface',
220
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
221
                ],
222
                'DeleteSuperAction' => [
223
                    EntityManagerInterface::class,
224
                    '\\Psr\\Log\\LoggerInterface',
225
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
226
                ],
227
                'AddDummyAction' => [
228
                    EntityManagerInterface::class,
229
                    '\\Zend\\Hydrator\\ClassMethods',
230
                    'DummyInputFilter',
231
                    '\\Psr\\Log\\LoggerInterface',
232
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
233
                ],
234
                'UpdateDummyAction' => [
235
                    EntityManagerInterface::class,
236
                    '\\Zend\\Hydrator\\ClassMethods',
237
                    'DummyInputFilter',
238
                    '\\Psr\\Log\\LoggerInterface',
239
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
240
                ],
241
                'GetDummyAction' => [
242
                    EntityManagerInterface::class,
243
                    '\\Psr\\Log\\LoggerInterface',
244
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
245
                ],
246
                'GetsDummyAction' => [
247
                    EntityManagerInterface::class,
248
                    '\\Psr\\Log\\LoggerInterface',
249
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
250
                ],
251
                'DeleteDummyAction' => [
252
                    EntityManagerInterface::class,
253
                    '\\Psr\\Log\\LoggerInterface',
254
                    '\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor',
255
                ],
256
            ],
257
            'dependencies' => [
258
                'delegators' => [
259
                    '\\Zend\\Expressive\\Application' => [
260
                        'Routes',
261
                    ],
262
                ],
263
            ],
264
            'doctrine' => [
265
                'paths' => [
266
                    'src/Dummy/Entities'
267
                ],
268
            ],
269
            'input_filter_specs' => [
270
                'SuperInputFilter' => [
271
                    'bar' => [
272
                        'required' => true,
273
                    ],
274
                    'baz' => [
275
                        'required' => true,
276
                    ],
277
                ],
278
                'DummyInputFilter' => [
279
                    'bar' => [
280
                        'required' => true,
281
                    ],
282
                    'baz' => [
283
                        'required' => true,
284
                    ],
285
                ],
286
            ],
287
        ];
288
289
        $this->assertEquals($expected, $actual);
290
    }
291
292
    public function testGetClassName()
293
    {
294
        $this->assertSame('A\\B\\ConfigProvider', (new Config($this->provider->reveal()))->getClassName());
295
    }
296
}
297