Passed
Pull Request — master (#116)
by Théo
02:03
created

PrinterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 283
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 283
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_it_can_provide_an_error_requirement_message() 0 12 1
A test_it_can_print_a_title() 0 15 1
A test_it_can_print_a_block() 0 16 1
B provideTitles() 0 79 1
B provideBlocks() 0 89 1
B provideErrorRequirements() 0 39 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\RequirementChecker;
16
17
use PHPUnit\Framework\TestCase;
18
use function ob_get_clean;
19
use function ob_start;
20
21
/**
22
 * @covers \KevinGH\RequirementChecker\Printer
23
 */
24
class PrinterTest extends TestCase
25
{
26
    /**
27
     * @dataProvider provideTitles
28
     */
29
    public function test_it_can_print_a_title(
30
        int $verbosity,
31
        bool $colors,
32
        int $width,
33
        string $message,
34
        int $messageVerbosity,
35
        string $expected
36
    ): void {
37
        $printer = new Printer($verbosity, $colors, $width);
38
39
        ob_start();
40
        $printer->title($message, $messageVerbosity);
41
        $actual = ob_get_clean();
42
43
        $this->assertSame($expected, $actual);
44
    }
45
46
    /**
47
     * @dataProvider provideErrorRequirements
48
     */
49
    public function test_it_can_provide_an_error_requirement_message(
50
        Requirement $requirement,
51
        int $verbosity,
52
        bool $colors,
53
        int $width,
54
        ?string $expected
55
    ): void {
56
        $printer = new Printer($verbosity, $colors, $width);
57
58
        $actual = $printer->getRequirementErrorMessage($requirement);
59
60
        $this->assertSame($expected, $actual);
61
    }
62
63
    /**
64
     * @dataProvider provideBlocks
65
     */
66
    public function test_it_can_print_a_block(
67
        int $verbosity,
68
        bool $colors,
69
        int $width,
70
        string $title,
71
        string $message,
72
        int $messageVerbosity,
73
        string $expected
74
    ): void {
75
        $printer = new Printer($verbosity, $colors, $width);
76
77
        ob_start();
78
        $printer->block($title, $message, $messageVerbosity, 'success');
79
        $actual = ob_get_clean();
80
81
        $this->assertSame($expected, $actual);
82
    }
83
84
    public function provideTitles()
85
    {
86
        yield [
87
            IO::VERBOSITY_NORMAL,
88
            false,
89
            50,
90
            'This is a title',
91
            IO::VERBOSITY_NORMAL,
92
            <<<'EOF'
93
94
This is a title
95
===============
96
97
98
EOF
99
        ];
100
101
        yield [
102
            IO::VERBOSITY_NORMAL,
103
            true,
104
            50,
105
            'This is a title',
106
            IO::VERBOSITY_NORMAL,
107
            <<<'EOF'
108

109
This is a title
110
===============
111

112

113
EOF
114
        ];
115
116
        yield [
117
            IO::VERBOSITY_VERBOSE,
118
            false,
119
            50,
120
            'This is a title',
121
            IO::VERBOSITY_NORMAL,
122
            <<<'EOF'
123
124
This is a title
125
===============
126
127
128
EOF
129
        ];
130
131
        yield [
132
            IO::VERBOSITY_NORMAL,
133
            false,
134
            50,
135
            'This is a title',
136
            IO::VERBOSITY_VERBOSE,
137
            '',
138
        ];
139
140
        yield [
141
            IO::VERBOSITY_NORMAL,
142
            false,
143
            15,
144
            'This is a very long title',
145
            IO::VERBOSITY_NORMAL,
146
            <<<'EOF'
147
148
This is a very
149
long title
150
===============
151
152
153
EOF
154
        ];
155
156
        yield [
157
            IO::VERBOSITY_NORMAL,
158
            true,
159
            15,
160
            'This is a very long title',
161
            IO::VERBOSITY_NORMAL,
162
            <<<'EOF'
163

164
This is a very
165
long title
166
===============
167

168

169
EOF
170
        ];
171
    }
172
173
    public function provideErrorRequirements()
174
    {
175
        yield [
176
            new Requirement(
177
                'return true;',
178
                'Test message',
179
                'Help message'
180
            ),
181
            IO::VERBOSITY_NORMAL,
182
            false,
183
            50,
184
            null,
185
        ];
186
187
        yield [
188
            new Requirement(
189
                'return false;',
190
                'Test message',
191
                'Help message'
192
            ),
193
            IO::VERBOSITY_NORMAL,
194
            false,
195
            50,
196
            <<<'EOF'
197
Test message
198
199
EOF
200
        ];
201
202
        yield [
203
            new Requirement(
204
                'return false;',
205
                'Test message',
206
                'Help message'
207
            ),
208
            IO::VERBOSITY_NORMAL,
209
            true,
210
            50,
211
            <<<'EOF'
212
Test message
213
214
EOF
215
        ];
216
    }
217
218
    public function provideBlocks()
219
    {
220
        yield [
221
            IO::VERBOSITY_NORMAL,
222
            false,
223
            25,
224
            'OK',
225
            'This is a block',
226
            IO::VERBOSITY_NORMAL,
227
            <<<'EOF'
228
229
                         
230
 [OK] This is a block    
231
                         
232
233
EOF
234
        ];
235
236
        yield [
237
            IO::VERBOSITY_NORMAL,
238
            true,
239
            25,
240
            'OK',
241
            'This is a block',
242
            IO::VERBOSITY_NORMAL,
243
            <<<'EOF'
244

245
                         
246
 [OK] This is a block    
247
                         
248

249
EOF
250
        ];
251
252
        yield [
253
            IO::VERBOSITY_VERBOSE,
254
            false,
255
            25,
256
            'OK',
257
            'This is a block',
258
            IO::VERBOSITY_NORMAL,
259
            <<<'EOF'
260
261
                         
262
 [OK] This is a block    
263
                         
264
265
EOF
266
        ];
267
268
        yield [
269
            IO::VERBOSITY_NORMAL,
270
            false,
271
            25,
272
            'OK',
273
            'This is a block',
274
            IO::VERBOSITY_VERBOSE,
275
            '',
276
        ];
277
278
        yield [
279
            IO::VERBOSITY_NORMAL,
280
            false,
281
            20,
282
            'OK',
283
            'This is a very long block that should be displayed on 5 lines',
284
            IO::VERBOSITY_NORMAL,
285
            <<<'EOF'
286
287
                    
288
 [OK] This is a     
289
      very long     
290
      block that    
291
      should be     
292
      displayed     
293
      on 5 lines    
294
                    
295
296
EOF
297
        ];
298
299
        yield [
300
            IO::VERBOSITY_NORMAL,
301
            true,
302
            20,
303
            'OK',
304
            'This is a very long block that should be displayed on 5 lines',
305
            IO::VERBOSITY_NORMAL,
306
            <<<'EOF'
307

308
                    
309
 [OK] This is a     
310
      very long     
311
      block that    
312
      should be     
313
      displayed     
314
      on 5 lines    
315
                    
316

317
EOF
318
        ];
319
    }
320
}
321