Skip to content

Commit 3075426

Browse files
committed
Revert "Use factories/interfaces correctly"
This reverts commit b52f7c6.
1 parent 81f8f63 commit 3075426

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Console\Command\Command;
1111
use Magento\Framework\Mview\View;
12-
use Magento\Framework\Mview\View\CollectionFactory;
13-
use Magento\Framework\Console\Cli;
1412

1513
/**
1614
* Command for displaying status of mview indexers.
1715
*/
1816
class IndexerStatusMviewCommand extends Command
1917
{
20-
/** @var \Magento\Framework\Mview\View\CollectionInterface $mviewCollection */
21-
private $mviewCollection;
18+
/** @var \Magento\Framework\Mview\View\CollectionInterface $mviewIndexersCollection */
19+
private $mviewIndexersCollection;
2220

2321
public function __construct(
24-
CollectionFactory $collectionFactory
22+
\Magento\Framework\Mview\View\CollectionInterface $collection
2523
) {
26-
$this->mviewCollection = $collectionFactory->create();
27-
24+
$this->mviewIndexersCollection = $collection;
2825
parent::__construct();
2926
}
3027

@@ -50,10 +47,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
5047

5148
$rows = [];
5249

53-
/** @var \Magento\Framework\Mview\View $view */
54-
foreach ($this->mviewCollection as $view) {
55-
$state = $view->getState();
56-
$changelog = $view->getChangelog();
50+
/** @var \Magento\Framework\Mview\View $indexer */
51+
foreach ($this->mviewIndexersCollection as $indexer) {
52+
$state = $indexer->getState();
53+
$changelog = $indexer->getChangelog();
5754

5855
try {
5956
$currentVersionId = $changelog->getVersion();
@@ -69,11 +66,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
6966
}
7067

7168
$rows[] = [
72-
$view->getId(),
73-
$state->getMode(),
74-
$state->getStatus(),
75-
$state->getUpdated(),
76-
$state->getVersionId(),
69+
$indexer->getData('view_id'),
70+
$state->getData('mode'),
71+
$state->getData('status'),
72+
$state->getData('updated'),
73+
$state->getData('version_id'),
7774
$pendingString,
7875
];
7976
}
@@ -85,14 +82,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8582
$table->addRows($rows);
8683
$table->render($output);
8784

88-
return Cli::RETURN_SUCCESS;
85+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
8986
} catch (\Exception $e) {
9087
$output->writeln('<error>' . $e->getMessage() . '</error>');
9188
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
9289
$output->writeln($e->getTraceAsString());
9390
}
9491

95-
return Cli::RETURN_FAILURE;
92+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
9693
}
9794
}
9895
}

app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Symfony\Component\Console\Helper\TableHelper;
1313
use Magento\Store\Model\Website;
1414
use Magento\Framework\Console\Cli;
15-
use Magento\Framework\Mview\View\CollectionFactory;
1615

1716
/**
1817
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -46,15 +45,9 @@ protected function setUp()
4645
$isLoadedProperty->setAccessible(true);
4746
$isLoadedProperty->setValue($this->collection, true);
4847

49-
$collectionFactory = $this->getMockBuilder(CollectionFactory::class)
50-
->disableOriginalConstructor()
51-
->getMock();
52-
$collectionFactory->method('create')
53-
->willReturn($this->collection);
54-
5548
$this->command = $this->objectManager->getObject(
5649
IndexerStatusMviewCommand::class,
57-
['collectionFactory' => $collectionFactory]
50+
['collection' => $this->collection]
5851
);
5952

6053
/** @var HelperSet $helperSet */
@@ -73,8 +66,6 @@ public function testExecute()
7366
[
7467
'view' => [
7568
'view_id' => 'catalog_category_product',
76-
],
77-
'state' => [
7869
'mode' => 'enabled',
7970
'status' => 'idle',
8071
'updated' => '2017-01-01 11:11:11',
@@ -87,8 +78,6 @@ public function testExecute()
8778
[
8879
'view' => [
8980
'view_id' => 'catalog_product_category',
90-
],
91-
'state' => [
9281
'mode' => 'disabled',
9382
'status' => 'idle',
9483
'updated' => '2017-01-01 11:11:11',
@@ -101,8 +90,6 @@ public function testExecute()
10190
[
10291
'view' => [
10392
'view_id' => 'catalog_product_attribute',
104-
],
105-
'state' => [
10693
'mode' => 'enabled',
10794
'status' => 'idle',
10895
'updated' => '2017-01-01 11:11:11',
@@ -115,7 +102,7 @@ public function testExecute()
115102
];
116103

117104
foreach ($mviews as $data) {
118-
$this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'], $data['state']));
105+
$this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog']));
119106
}
120107
$this->collection->addItem($this->getNeverEnabledMviewIndexerWithNoTable());
121108

@@ -166,19 +153,18 @@ public function testExecute()
166153
/**
167154
* @param array $viewData
168155
* @param array $changelogData
169-
* @param array $stateData
170156
* @return Mview\View|Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject
171157
*/
172-
protected function generateMviewStub(array $viewData, array $changelogData, array $stateData)
158+
protected function generateMviewStub(array $viewData, array $changelogData)
173159
{
174160
/** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */
175161
$changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class)
176162
->disableOriginalConstructor()
177163
->getMock();
178164

179165
$list = [];
180-
if ($changelogData['version_id'] !== $stateData['version_id']) {
181-
$list = range($stateData['version_id']+1, $changelogData['version_id']);
166+
if ($changelogData['version_id'] !== $viewData['version_id']) {
167+
$list = range($viewData['version_id']+1, $changelogData['version_id']);
182168
}
183169

184170
$changelog->expects($this->any())
@@ -189,14 +175,6 @@ protected function generateMviewStub(array $viewData, array $changelogData, arra
189175
->method('getVersion')
190176
->willReturn($changelogData['version_id']);
191177

192-
/** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stub */
193-
$state = $this->getMockBuilder(\Magento\Indexer\Model\Mview\View\State::class)
194-
->disableOriginalConstructor()
195-
->setMethods(['loadByView'])
196-
->getMock();
197-
198-
$state->setData($stateData);
199-
200178
/** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */
201179
$stub = $this->getMockBuilder(\Magento\Framework\Mview\View::class)
202180
->disableOriginalConstructor()
@@ -209,7 +187,7 @@ protected function generateMviewStub(array $viewData, array $changelogData, arra
209187

210188
$stub->expects($this->any())
211189
->method('getState')
212-
->willReturn($state);
190+
->willReturnSelf();
213191

214192
$stub->setData($viewData);
215193

0 commit comments

Comments
 (0)