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 StyleTest extends TestCase |
||
13 | { |
||
14 | use TesterTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
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', 'w+', false)); |
||
25 | $formatter = new FormatterHelper(); |
||
26 | $this->style = new Style($input, $this->output, $formatter); |
||
27 | } |
||
28 | |||
29 | public function testTimer(): void |
||
30 | { |
||
31 | $this->style->timer(); |
||
32 | $this->assertRegExp('/\[ 000000000.00[\d]{2} \]/', $this->getDisplay()); |
||
33 | |||
34 | $this->style->timer(true); |
||
35 | $this->assertRegExp('/\[ 000000000.00[\d]{2} \]\n/', $this->getDisplay()); |
||
36 | } |
||
37 | |||
38 | public function testFormatSection(): void |
||
39 | { |
||
40 | $this->style->formatSection('Section', 'Format Section info (default)'); |
||
41 | $this->assertEquals("[Section] Format Section info (default)\n", $this->getDisplay()); |
||
42 | } |
||
43 | |||
44 | public function testFormatBlockArray(): void |
||
45 | { |
||
46 | $expect = <<<EOT |
||
47 | <ok> </ok> |
||
48 | <ok> m1 </ok> |
||
49 | <ok> </ok> |
||
50 | <ok> </ok> |
||
51 | <ok> m2 </ok> |
||
52 | <ok> </ok> |
||
53 | |||
54 | EOT; |
||
55 | |||
56 | $this->style->formatBlock(['m1', 'm2'], 'ok', true); |
||
57 | $this->assertEquals($expect, $this->getDisplay()); |
||
58 | } |
||
59 | |||
60 | public function testFormatBlock(): void |
||
61 | { |
||
62 | $expect = <<<EOT |
||
63 | <ok> </ok> |
||
64 | <ok> m1 </ok> |
||
65 | <ok> </ok> |
||
66 | |||
67 | EOT; |
||
68 | |||
69 | $this->style->formatBlock('m1', 'ok', true); |
||
70 | $this->assertEquals($expect, $this->getDisplay()); |
||
71 | } |
||
72 | |||
73 | public function testErrorLine(): void |
||
74 | { |
||
75 | $this->style->errorLine(['m1']); |
||
76 | $this->assertEquals(" m1 \n", $this->getDisplay()); |
||
77 | } |
||
78 | |||
79 | public function testGenericBlock(): void |
||
80 | { |
||
81 | $expected = <<<EOT |
||
82 | |||
83 | [ERROR] m1 |
||
84 | |||
85 | |||
86 | |||
87 | EOT; |
||
88 | |||
89 | $this->style->genericBlock('m1', 'red', 'error', 50); |
||
90 | $this->assertEquals($expected, $this->getDisplay()); |
||
91 | } |
||
92 | |||
93 | public function testGenericBlockWithMissingType(): void |
||
94 | { |
||
95 | $this->style->genericBlock('m1', 'red', ''); |
||
96 | $this->assertEquals('', $this->getDisplay()); |
||
97 | } |
||
98 | |||
99 | public function testNote(): void |
||
100 | { |
||
101 | $expected = <<<EOT |
||
102 | |||
103 | [NOTE] m1 |
||
104 | |||
105 | |||
106 | |||
107 | EOT; |
||
108 | |||
109 | $this->style->note('m1'); |
||
110 | $this->assertEquals($expected, $this->getDisplay()); |
||
111 | } |
||
112 | |||
113 | public function testCaution(): void |
||
114 | { |
||
115 | $expected = <<<EOT |
||
116 | |||
117 | [CAUTION] m1 |
||
118 | |||
119 | |||
120 | |||
121 | EOT; |
||
122 | |||
123 | $this->style->caution('m1'); |
||
124 | $this->assertEquals($expected, $this->getDisplay()); |
||
125 | } |
||
126 | |||
127 | public function testSuccess(): void |
||
128 | { |
||
129 | $expected = <<<EOT |
||
130 | |||
131 | [SUCCESS] m1 |
||
132 | |||
133 | |||
134 | |||
135 | EOT; |
||
136 | |||
137 | $this->style->success('m1'); |
||
138 | $this->assertEquals($expected, $this->getDisplay()); |
||
139 | } |
||
140 | |||
141 | public function testWarning(): void |
||
142 | { |
||
143 | $expected = <<<EOT |
||
144 | |||
145 | [WARNING] m1 |
||
146 | |||
147 | |||
148 | |||
149 | EOT; |
||
150 | |||
151 | $this->style->warning('m1'); |
||
152 | $this->assertEquals($expected, $this->getDisplay()); |
||
153 | } |
||
154 | |||
155 | public function testError(): void |
||
156 | { |
||
157 | $expected = <<<EOT |
||
158 | |||
159 | [ERROR] m1 |
||
160 | |||
161 | |||
162 | |||
163 | EOT; |
||
164 | |||
165 | $this->style->error('m1'); |
||
166 | $this->assertEquals($expected, $this->getDisplay()); |
||
167 | } |
||
168 | } |
||
169 |