9 use Symfony\Component\Console\Tester\CommandTester;
10 use Symfony\Component\Console\Helper\HelperSet;
28 private $websiteRepositoryMock;
33 private $objectManager;
37 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
39 $this->websiteRepositoryMock = $this->getMockForAbstractClass(WebsiteRepositoryInterface::class);
41 $this->command = $this->objectManager->getObject(
42 WebsiteListCommand::class,
43 [
'websiteManagement' => $this->websiteRepositoryMock]
49 $this->websiteRepositoryMock->expects($this->any())
51 ->willThrowException(
new \Exception(
"Dummy test exception"));
53 $tester =
new CommandTester($this->command);
56 $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay()));
57 $this->assertEquals(
'Dummy test exception', $linesOutput[0]);
64 'default_group_id' =>
'555',
65 'name' =>
'unit test website',
66 'code' =>
'unit_test_website',
68 'sort_order' =>
'987',
72 $this->objectManager->getObject(Website::class)->setData($websiteData),
75 $this->websiteRepositoryMock->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(
'Default Group Id', trim($headerValues[1]));
92 $this->assertEquals(
'Name', trim($headerValues[2]));
93 $this->assertEquals(
'Code', trim($headerValues[3]));
94 $this->assertEquals(
'Sort Order', trim($headerValues[4]));
95 $this->assertEquals(
'Is Default', trim($headerValues[5]));
97 $websiteValues = array_values(array_filter(explode(
'|', $linesOutput[3])));
98 $this->assertEquals(
'444', trim($websiteValues[0]));
99 $this->assertEquals(
'555', trim($websiteValues[1]));
100 $this->assertEquals(
'unit test website', trim($websiteValues[2]));
101 $this->assertEquals(
'unit_test_website', trim($websiteValues[3]));
102 $this->assertEquals(
'987', trim($websiteValues[4]));
103 $this->assertEquals(
'0', trim($websiteValues[5]));
testExecuteExceptionNoVerbosity()