1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
7
|
|
|
use Symfony\Component\Console\Output\StreamOutput; |
8
|
|
|
use Symfony\Component\Console\Helper\FormatterHelper; |
9
|
|
|
use Symfony\Component\Console\Tester\TesterTrait; |
10
|
|
|
use BlueConsole\Style; |
11
|
|
|
|
12
|
|
|
class AdditionalTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
use TesterTrait; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Style |
18
|
|
|
*/ |
19
|
|
|
protected $style; |
20
|
|
|
|
21
|
|
|
public function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$input = new ArgvInput(); |
24
|
|
|
$this->output = new StreamOutput(\fopen('php://memory', 'wb+', false)); |
25
|
|
|
$formatter = new FormatterHelper(); |
26
|
|
|
$this->style = new Style($input, $this->output, $formatter); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testTruncateMessage(): void |
30
|
|
|
{ |
31
|
|
|
$message = $this->style->truncateMessage('1234567890', 5); |
32
|
|
|
$this->assertEquals('12345...', $message); |
33
|
|
|
|
34
|
|
|
$message = $this->style->truncateMessage('1234567890', 5, '-'); |
35
|
|
|
$this->assertEquals('12345-', $message); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testTruncate(): void |
39
|
|
|
{ |
40
|
|
|
$this->style->truncate('1234567890', 5); |
41
|
|
|
$this->assertEquals('12345...', $this->getDisplay()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testTruncateWithSuffix(): void |
45
|
|
|
{ |
46
|
|
|
$this->style->truncate('1234567890', 5, '_'); |
47
|
|
|
$this->assertEquals('12345_', $this->getDisplay()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testTruncateLn(): void |
51
|
|
|
{ |
52
|
|
|
$this->style->truncateLn('1234567890', 5); |
53
|
|
|
$this->assertEquals("12345...\n", $this->getDisplay()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testAlignGrtSet(): void |
57
|
|
|
{ |
58
|
|
|
$this->assertEquals(12, $this->style->getAlign()); |
59
|
|
|
$this->assertInstanceOf(Style::class, $this->style->setAlign(100)); |
60
|
|
|
$this->assertEquals(100, $this->style->getAlign()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider alignDataProvider |
65
|
|
|
*/ |
66
|
|
|
public function testAlign($string, $expect): void |
67
|
|
|
{ |
68
|
|
|
$this->assertEquals($expect, $this->style->align($string, 15)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function alignDataProvider(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
[ |
75
|
|
|
'string' => 5, |
76
|
|
|
'expect' => ' ', |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'string' => '5', |
80
|
|
|
'expect' => ' ', |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'string' => ['123', '456'], |
84
|
|
|
'expect' => ' ', |
85
|
|
|
], |
86
|
|
|
[ |
87
|
|
|
'string' => null, |
88
|
|
|
'expect' => ' ', |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|