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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use PHPUnit\Framework\TestCase;
/**
* @covers \PHPUnit\Util\Color
* @testdox Basic ANSI color highlighting support
* @small
*/
final class ColorTest extends TestCase
{
/**
* @testdox Colorize with $_dataName
* @dataProvider colorizeProvider
*/
public function testColorize(string $color, string $buffer, string $expected): void
{
$this->assertSame($expected, Color::colorize($color, $buffer));
}
/**
* @testdox Colorize path $path after $prevPath
* @dataProvider colorizePathProvider
*/
public function testColorizePath(?string $prevPath, string $path, bool $colorizeFilename, string $expected): void
{
$this->assertSame($expected, Color::colorizePath($path, $prevPath, $colorizeFilename));
}
/**
* @testdox dim($m) and colorize('dim',$m) return different ANSI codes
*/
public function testDimAndColorizeDimAreDifferent(): void
{
$buffer = 'some string';
$this->assertNotSame(Color::dim($buffer), Color::colorize('dim', $buffer));
}
/**
* @testdox Visualize all whitespace characters in $actual
* @dataProvider whitespacedStringProvider
*/
public function testVisibleWhitespace(string $actual, string $expected): void
{
$this->assertSame($expected, Color::visualizeWhitespace($actual, true));
}
/**
* @testdox Visualize whitespace but ignore EOL
*/
public function testVisibleWhitespaceWithoutEOL(): void
{
$string = "line1\nline2\n";
$this->assertSame($string, Color::visualizeWhitespace($string, false));
}
/**
* @dataProvider unnamedDataSetProvider
*/
public function testPrettifyUnnamedDataprovider(int $value): void
{
$this->assertSame($value, $value);
}
/**
* @dataProvider namedDataSetProvider
*/
public function testPrettifyNamedDataprovider(int $value): void
{
$this->assertSame($value, $value);
}
/**
* @testdox TestDox shows name of data set $_dataName with value $value
* @dataProvider namedDataSetProvider
*/
public function testTestdoxDatanameAsParameter(int $value): void
{
$this->assertSame($value, $value);
}
public function colorizeProvider(): array
{
return [
'no color' => ['', 'string', 'string'],
'one color' => ['fg-blue', 'string', "\x1b[34mstring\x1b[0m"],
'multiple colors' => ['bold,dim,fg-blue,bg-yellow', 'string', "\x1b[1;2;34;43mstring\x1b[0m"],
'invalid color' => ['fg-invalid', 'some text', 'some text'],
'valid and invalid colors' => ['fg-invalid,bg-blue', 'some text', "\e[44msome text\e[0m"],
];
}
public function colorizePathProvider(): array
{
$sep = DIRECTORY_SEPARATOR;
$sepDim = Color::dim($sep);
return [
'null previous path' => [
null,
$sep . 'php' . $sep . 'unit' . $sep . 'test.phpt',
false,
$sepDim . 'php' . $sepDim . 'unit' . $sepDim . 'test.phpt',
],
'empty previous path' => [
'',
$sep . 'php' . $sep . 'unit' . $sep . 'test.phpt',
false,
$sepDim . 'php' . $sepDim . 'unit' . $sepDim . 'test.phpt',
],
'from root' => [
$sep,
$sep . 'php' . $sep . 'unit' . $sep . 'test.phpt',
false,
$sepDim . 'php' . $sepDim . 'unit' . $sepDim . 'test.phpt',
],
'partial part' => [
$sep . 'php' . $sep,
$sep . 'php' . $sep . 'unit' . $sep . 'test.phpt',
false,
Color::dim($sep . 'php' . $sep) . 'unit' . $sepDim . 'test.phpt',
],
'colorize filename' => [
'',
$sep . '_d-i.r' . $sep . 't-e_s.t.phpt',
true,
$sepDim . '_d-i.r' . $sepDim . 't' . Color::dim('-') . 'e' . Color::dim('_') . 's' . Color::dim('.') . 't' . Color::dim('.phpt'),
],
];
}
public function whitespacedStringProvider(): array
{
return [
['no-spaces',
'no-spaces',
],
[
' space invaders ',
"\e[2m·\e[22mspace\e[2m···\e[22minvaders\e[2m·\e[22m",
],
[
"\tindent, space and \\n\n\\r\r",
"\e[2m⇥\e[22mindent,\e[2m·\e[22mspace\e[2m·\e[22mand\e[2m·\e[22m\\n\e[2m↵\e[22m\\r\e[2m⟵\e[22m",
],
];
}
public function unnamedDataSetProvider(): array
{
return [
[1],
[2],
];
}
public function namedDataSetProvider(): array
{
return [
'one' => [1],
'two' => [2],
];
}
}
|