-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandTestCase.php
More file actions
44 lines (33 loc) · 908 Bytes
/
CommandTestCase.php
File metadata and controls
44 lines (33 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Syntatis\Tests\Commands;
use PHPUnit\Framework\TestCase;
use function preg_replace;
use function str_replace;
use function trim;
abstract class CommandTestCase extends TestCase
{
protected static function normalizeOutput(string $value): string
{
$output = self::canonicalize($value);
$output = str_replace("\n", ' ', $output);
$output = preg_replace('/\s+/', ' ', $output);
if ($output === null) {
return $value;
}
return trim($output);
}
protected static function canonicalize(string $str): string
{
// normalize EOL style
$str = str_replace("\r\n", "\n", $str);
// trim newlines at end
$str = rtrim($str, "\n");
// remove trailing whitespace on all lines
$lines = explode("\n", $str);
$lines = array_map(static function ($line): string {
return rtrim($line, " \t");
}, $lines);
return implode("\n", $lines);
}
}