9 use Symfony\Component\Console\Tester\CommandTester;
10 use Symfony\Component\Console\Helper\HelperSet;
27 private $storeManagerMock;
32 private $objectManager;
36 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38 $this->storeManagerMock = $this->getMockForAbstractClass(\
Magento\
Store\Model\StoreManagerInterface::class);
40 $this->command = $this->objectManager->getObject(
41 StoreListCommand::class,
42 [
'storeManager' => $this->storeManagerMock]
48 $this->storeManagerMock->expects($this->any())
50 ->willThrowException(
new \Exception(
"Dummy test exception"));
52 $tester =
new CommandTester($this->command);
55 $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay()));
56 $this->assertEquals(
'Dummy test exception', $linesOutput[0]);
64 'website_id' =>
'888',
65 'name' =>
'unit test store',
66 'code' =>
'unit_test_store',
68 'sort_order' =>
'123',
72 $this->objectManager->getObject(Store::class)->setData($storeData),
75 $this->storeManagerMock->expects($this->any())
79 $tester =
new CommandTester($this->command);
82 $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay()));
83 $this->assertCount(5, $linesOutput,
'There should be 5 lines output. 3 Spacers, 1 header, 1 content.');
85 $this->assertEquals($linesOutput[0], $linesOutput[2],
"Lines 0, 2, 4 should be spacer lines");
86 $this->assertEquals($linesOutput[2], $linesOutput[4],
"Lines 0, 2, 4 should be spacer lines");
88 $headerValues = array_values(array_filter(explode(
'|', $linesOutput[1])));
90 $this->assertEquals(
'ID', trim($headerValues[0]));
91 $this->assertEquals(
'Website ID', trim($headerValues[1]));
92 $this->assertEquals(
'Group ID', trim($headerValues[2]));
93 $this->assertEquals(
'Name', trim($headerValues[3]));
94 $this->assertEquals(
'Code', trim($headerValues[4]));
95 $this->assertEquals(
'Sort Order', trim($headerValues[5]));
96 $this->assertEquals(
'Is Active', trim($headerValues[6]));
98 $storeValues = array_values(array_filter(explode(
'|', $linesOutput[3])));
99 $this->assertEquals(
'999', trim($storeValues[0]));
100 $this->assertEquals(
'888', trim($storeValues[1]));
101 $this->assertEquals(
'777', trim($storeValues[2]));
102 $this->assertEquals(
'unit test store', trim($storeValues[3]));
103 $this->assertEquals(
'unit_test_store', trim($storeValues[4]));
104 $this->assertEquals(
'123', trim($storeValues[5]));
105 $this->assertEquals(
'1', trim($storeValues[6]));
testExecuteExceptionNoVerbosity()