ConfigHelperTest::provideScenarios()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 165
Code Lines 95

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 95
nc 1
nop 0
dl 0
loc 165
rs 8.109
c 2
b 0
f 1

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
namespace NeedleProject\LaravelRabbitMq;
3
4
use PHPUnit\Framework\TestCase;
5
6
class ConfigHelperTest extends TestCase
7
{
8
    /**
9
     * @dataProvider provideScenarios
10
     * @param $inputConfig
11
     * @param $expectedConfig
12
     */
13
    public function testDefaultsForMainKeys($inputConfig, $expectedConfig)
14
    {
15
        $configHelper = new ConfigHelper();
16
        $newConfig = $configHelper->addDefaults($inputConfig);
17
18
        $this->assertEquals($expectedConfig, $newConfig);
19
    }
20
21
    public static function provideScenarios(): array
22
    {
23
        return [
24
            // first scenario -- add root keys
25
            [
26
                [],
27
                [
28
                    'connections' => [],
29
                    'exchanges' => [],
30
                    'queues' => [],
31
                    'publishers' => [],
32
                    'consumers' => []
33
                ]
34
            ],
35
            // second scenario -- add attributes on queues
36
            [
37
                [
38
                    'connections' => [
39
                        'bar' => []
40
                    ],
41
                    'queues' => [
42
                        'foo' => [
43
                            'name' => 'foo.bar',
44
                            'connection' => 'bar'
45
                        ]
46
                    ]
47
                ],
48
                [
49
                    'connections' => [
50
                        'bar' => []
51
                    ],
52
                    'queues' => [
53
                        'foo' => [
54
                            'name' => 'foo.bar',
55
                            'connection' => 'bar',
56
                            'attributes' => []
57
                        ]
58
                    ],
59
                    'exchanges' => [],
60
                    'publishers' => [],
61
                    'consumers' => []
62
                ]
63
            ],
64
            // third scenario -- add prefetch_count and global_prefetch on consumer
65
            [
66
                [
67
                    'connections' => [
68
                        'bar' => []
69
                    ],
70
                    'queues' => [
71
                        'foo' => [
72
                            'name' => 'foo.bar',
73
                            'connection' => 'bar'
74
                        ]
75
                    ],
76
                    'consumers' => [
77
                        'foo_consumer' => [
78
                            'queue' => 'foo',
79
                            'message_processor' => 'BAR'
80
                        ]
81
                    ]
82
                ],
83
                [
84
                    'connections' => [
85
                        'bar' => []
86
                    ],
87
                    'queues' => [
88
                        'foo' => [
89
                            'name' => 'foo.bar',
90
                            'connection' => 'bar',
91
                            'attributes' => []
92
                        ]
93
                    ],
94
                    'exchanges' => [],
95
                    'publishers' => [],
96
                    'consumers' => [
97
                        'foo_consumer' => [
98
                            'queue' => 'foo',
99
                            'prefetch_count' => 1,
100
                            'global_prefetch' => true,
101
                            'message_processor' => 'BAR'
102
                        ]
103
                    ]
104
                ]
105
            ],
106
            // 4th scenario -- don't override prefetch_count and global_prefetch on consumer
107
            [
108
                [
109
                    'connections' => [
110
                        'bar' => []
111
                    ],
112
                    'queues' => [
113
                        'foo' => [
114
                            'name' => 'foo.bar',
115
                            'connection' => 'bar'
116
                        ]
117
                    ],
118
                    'consumers' => [
119
                        'foo_consumer' => [
120
                            'queue' => 'foo',
121
                            'prefetch_count' => 3,
122
                            'global_prefetch' => false,
123
                            'message_processor' => 'BAR'
124
                        ]
125
                    ]
126
                ],
127
                [
128
                    'connections' => [
129
                        'bar' => []
130
                    ],
131
                    'queues' => [
132
                        'foo' => [
133
                            'name' => 'foo.bar',
134
                            'connection' => 'bar',
135
                            'attributes' => []
136
                        ]
137
                    ],
138
                    'exchanges' => [],
139
                    'publishers' => [],
140
                    'consumers' => [
141
                        'foo_consumer' => [
142
                            'queue' => 'foo',
143
                            'prefetch_count' => 3,
144
                            'global_prefetch' => false,
145
                            'message_processor' => 'BAR'
146
                        ]
147
                    ]
148
                ]
149
            ],
150
            // 5th scenario -- add attributes on queues
151
            [
152
                [
153
                    'connections' => [
154
                        'bar' => []
155
                    ],
156
                    'queues' => [
157
                        'foo' => [
158
                            'name' => 'foo.bar',
159
                            'connection' => 'bar',
160
                            'attributes' => [
161
                                'bind'        => [
162
                                    ['exchange' => 'foobar']
163
                                ]
164
                            ]
165
                        ]
166
                    ]
167
                ],
168
                [
169
                    'connections' => [
170
                        'bar' => []
171
                    ],
172
                    'queues' => [
173
                        'foo' => [
174
                            'name' => 'foo.bar',
175
                            'connection' => 'bar',
176
                            'attributes' => [
177
                                'bind'        => [
178
                                    ['exchange' => 'foobar']
179
                                ]
180
                            ]
181
                        ]
182
                    ],
183
                    'exchanges' => [],
184
                    'publishers' => [],
185
                    'consumers' => []
186
                ]
187
            ],
188
        ];
189
    }
190
}
191