Skip to content

Commit cdbdebf

Browse files
author
Simon Mönch
authored
Merge branch 'master' into php8
2 parents 6daee08 + 9548271 commit cdbdebf

3 files changed

Lines changed: 69 additions & 22 deletions

File tree

requirement-checker/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
bootstrap="vendor/autoload.php"
55
colors="true">
66

7+
<php>
8+
<!-- The width is matching the Travis one to avoid any issues with the CI -->
9+
<env name="COLUMNS" value="80" />
10+
</php>
11+
712
<testsuites>
813
<testsuite name="RequirementChecker Test Suite">
914
<directory>tests/</directory>

requirement-checker/src/Printer.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function __construct($verbosity, $supportColors, $width = null)
3939
{
4040
if (null === $width) {
4141
$terminal = new Terminal();
42-
$width = min($terminal->getWidth(), 80);
42+
$width = $terminal->getWidth();
4343
}
4444

4545
$this->verbosity = $verbosity;
4646
$this->supportColors = $supportColors;
47-
$this->width = $width;
47+
$this->width = $width ?: 80;
4848
}
4949

5050
/**
@@ -112,24 +112,27 @@ public function getRequirementErrorMessage(Requirement $requirement)
112112
public function block($title, $message, $verbosity, $style = null)
113113
{
114114
$prefix = ' ['.$title.'] ';
115+
$lineLength = $this->width - strlen($prefix) - 1;
116+
if ($lineLength < 0) {
117+
$lineLength = 0;
118+
}
115119
$message = $prefix.trim($message);
116120

117121
$lines = array();
118122

119123
$remainingMessage = $message;
120124

121-
while ($remainingMessage !== '') {
122-
$wrapped = wordwrap($remainingMessage, $this->width - 3, '¬');
123-
$exploded = explode('¬', $wrapped);
124-
$line = $exploded[0];
125-
$remainingMessage = ltrim(substr($remainingMessage, \strlen($line)));
125+
$wrapped = wordwrap($remainingMessage, $lineLength, '¬');
126+
$wrapped = explode('¬', $wrapped);
126127

127-
if ($remainingMessage !== '') {
128-
$remainingMessage = str_repeat(' ', \strlen($prefix)).$remainingMessage;
128+
do {
129+
$line = array_shift($wrapped);
130+
if ($lines && $lineLength > 0) {
131+
$line = str_repeat(' ', \strlen($prefix)).ltrim($line);
129132
}
130-
131133
$lines[] = str_pad($line, $this->width, ' ', STR_PAD_RIGHT);
132134
}
135+
while (count($wrapped));
133136

134137
$this->printvln('', $verbosity);
135138
$this->printvln(str_repeat(' ', $this->width), $verbosity, $style);

requirement-checker/tests/PrinterTest.php

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public function provideBlocks(): Generator
226226
<<<'EOF'
227227
228228
229-
[OK] This is a block
229+
[OK] This is a
230+
block
230231

231232

232233
EOF
@@ -242,7 +243,8 @@ public function provideBlocks(): Generator
242243
<<<'EOF'
243244

244245
 
245-
 [OK] This is a block 
246+
 [OK] This is a 
247+
 block 
246248
 
247249

248250
EOF
@@ -258,7 +260,8 @@ public function provideBlocks(): Generator
258260
<<<'EOF'
259261
260262
261-
[OK] This is a block
263+
[OK] This is a
264+
block
262265

263266

264267
EOF
@@ -284,12 +287,12 @@ public function provideBlocks(): Generator
284287
<<<'EOF'
285288
286289
287-
[OK] This is a
288-
very long
290+
[OK] This is
291+
a very long
289292
block that
290293
should be
291-
displayed
292-
on 5 lines
294+
displayed on
295+
5 lines
293296

294297

295298
EOF
@@ -300,19 +303,55 @@ public function provideBlocks(): Generator
300303
true,
301304
20,
302305
'OK',
303-
'This is a very long block that should be displayed on 5 lines',
306+
'This is a very long block that should be displayed on 6 lines',
304307
IO::VERBOSITY_NORMAL,
305308
<<<'EOF'
306309

307310
 
308-
[0m[30;42m [OK] This is a [0m
309-
[0m[30;42m very long [0m
311+
[0m[30;42m [OK] This is [0m
312+
[0m[30;42m a very long [0m
310313
 block that 
311314
 should be 
312-
 displayed 
313-
 on 5 lines 
315+
 displayed on 
316+
 6 lines 
317+
 
318+

319+
EOF
320+
];
321+
322+
yield [
323+
IO::VERBOSITY_NORMAL,
324+
true,
325+
20,
326+
'OK',
327+
'Your system is ready to run the application.',
328+
IO::VERBOSITY_NORMAL,
329+
<<<'EOF'
330+

331+
 
332+
 [OK] Your 
333+
 system is 
334+
 ready to run 
335+
 the 
336+
 application. 
314337
 
315338

339+
EOF
340+
];
341+
342+
yield [
343+
IO::VERBOSITY_NORMAL,
344+
true,
345+
0,
346+
'OK',
347+
'Your system is ready to run the application.',
348+
IO::VERBOSITY_NORMAL,
349+
<<<'EOF'
350+

351+
 
352+
 [OK] Your system is ready to run the application. 
353+
 
354+

316355
EOF
317356
];
318357
}

0 commit comments

Comments
 (0)