11 use PHPUnit\Framework\TestCase;
12 use Symfony\Component\Console\Formatter\OutputFormatter;
13 use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
14 use Symfony\Component\Console\Helper\TableCell;
15 use Symfony\Component\Console\Input\ArrayInput;
16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputDefinition;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Output\OutputInterface;
31 private $magentoStyle;
45 $input =
new ArrayInput([
'name' =>
'foo'],
new InputDefinition([
new InputArgument(
'name')]));
47 $this->magentoStyle =
new MagentoStyle($input, $this->testOutput);
57 $this->magentoStyle->block(
58 [
'test first message',
'test second message'],
64 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
65 '<testBlockStyle>testBlockPrefix\[testBlockType\] test first message\s+' 66 . PHP_EOL .
'<testBlockStyle>testBlockPrefix\s+' 67 . PHP_EOL .
'<testBlockStyle>testBlockPrefix \s+ test second message\s+' 70 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Block does not match output');
80 $this->magentoStyle->title(
'My Title');
81 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
' My Title' . PHP_EOL .
' ========' . PHP_EOL . PHP_EOL;
82 $this->assertEquals($expected, $this->testOutput->output,
'Title does not match output');
92 $this->magentoStyle->section(
'My Section');
93 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
' My Section' . PHP_EOL .
' ----------' . PHP_EOL . PHP_EOL;
94 $this->assertEquals($expected, $this->testOutput->output,
'Section does not match output');
104 $this->magentoStyle->listing([
'test first element',
'test second element']);
105 $expected = PHP_EOL .
' * test first element' . PHP_EOL .
' * test second element' . PHP_EOL . PHP_EOL;
106 $this->assertEquals($expected, $this->testOutput->output,
'Listing does not match output');
116 $this->magentoStyle->text(
'test message');
117 $expected = PHP_EOL .
' test message' . PHP_EOL;
119 $this->assertEquals($expected, $this->testOutput->output,
'Text does not match output');
129 $this->magentoStyle->comment(
'test comment');
130 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
'\s+test comment\s+' . PHP_EOL . PHP_EOL;
131 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Comment does not match output');
141 $this->magentoStyle->success(
'test success message');
142 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
' \[SUCCESS\] test success message\s+' . PHP_EOL . PHP_EOL;
143 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Success message does not match output');
153 $this->magentoStyle->error(
'test error message');
154 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
'\s+\[ERROR\] test error message\s+' . PHP_EOL . PHP_EOL;
155 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Error message does not match output');
165 $this->magentoStyle->warning(
'test warning message');
166 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
'\s+\[WARNING\] test warning message\s+' . PHP_EOL . PHP_EOL;
167 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Warning message does not match output');
177 $this->magentoStyle->note(
'test note message');
178 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
'\s+\[NOTE\] test note message\s+' . PHP_EOL . PHP_EOL;
179 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Note message does not match output');
189 $this->magentoStyle->caution(
'test caution message');
190 $expected = PHP_EOL . PHP_EOL . PHP_EOL .
'\s+! \[CAUTION\] test caution message\s+' . PHP_EOL . PHP_EOL;
191 $this->assertRegExp(
'/' . $expected .
'/', $this->testOutput->output,
'Caution message does not match output');
202 [
new TableCell(
'Main table title', [
'colspan' => 2])],
203 [
'testHeader1',
'testHeader2',
'testHeader3'],
209 new TableCell(
'testValue3', [
'rowspan' => 2]),
211 [
'testValue4',
'testValue5'],
213 $this->magentoStyle->table($headers, $rows);
214 $expected =
' ------------- ------------- ------------- ' . PHP_EOL .
215 ' Main table title ' . PHP_EOL .
216 ' ------------- ------------- ------------- ' . PHP_EOL .
217 ' testHeader1 testHeader2 testHeader3 ' . PHP_EOL .
218 ' ------------- ------------- ------------- ' . PHP_EOL .
219 ' testValue1 testValue2 testValue3 ' . PHP_EOL .
220 ' testValue4 testValue5 ' . PHP_EOL .
221 ' ------------- ------------- ------------- ' . PHP_EOL . PHP_EOL;
223 $this->assertEquals($expected, $this->testOutput->output,
'Table does not match output');
232 $formatter = $this->getMockBuilder(OutputFormatter::class)
233 ->disableOriginalConstructor()
235 $input = $this->getMockBuilder(InputInterface::class)
236 ->setMethods([
'isInteractive'])
237 ->disableOriginalConstructor()
238 ->getMockForAbstractClass();
239 $input->expects($this->exactly(2))
240 ->method(
'isInteractive')
242 $output = $this->getMockBuilder(OutputInterface::class)
243 ->setMethods([
'getVerbosity',
'getFormatter'])
244 ->disableOriginalConstructor()
245 ->getMockForAbstractClass();
246 $output->expects($this->once())
247 ->method(
'getVerbosity')
249 $output->expects($this->once())
250 ->method(
'getFormatter')
251 ->willReturn($formatter);
259 $questionHelper = $this->getMockBuilder(SymfonyQuestionHelper::class)
260 ->disableOriginalConstructor()
262 $questionHelper->expects($this->once())
264 ->willReturn(
'test Answer');
265 $objectManager->setBackwardCompatibleProperty($magentoStyle,
'questionHelper', $questionHelper);
269 $magentoStyle->ask(
'test question?',
'test default')
280 $this->magentoStyle->progressStart(2);
281 $this->magentoStyle->progressAdvance(3);
282 $this->magentoStyle->progressFinish();
283 $expected =
' 0/2 [> ] 0%' . PHP_EOL .
284 ' 3/3 [============================] 100%' . PHP_EOL . PHP_EOL;
285 $this->assertEquals($expected, $this->testOutput->output,
'Progress does not match output');