Skip to content

Commit 9c4c3bb

Browse files
committed
MC-23978: Indexer:reindex return wrong status code
1 parent 390505a commit 9c4c3bb

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function configure()
7474
*/
7575
protected function execute(InputInterface $input, OutputInterface $output)
7676
{
77-
$returnValue = Cli::RETURN_FAILURE;
77+
$returnValue = Cli::RETURN_SUCCESS;
7878
foreach ($this->getIndexers($input) as $indexer) {
7979
try {
8080
$this->validateIndexerStatus($indexer);
@@ -97,14 +97,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
9797
$output->writeln(
9898
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', $resultTime)])
9999
);
100-
$returnValue = Cli::RETURN_SUCCESS;
101100
} catch (LocalizedException $e) {
102101
$output->writeln(__('exception: %message', ['message' => $e->getMessage()]));
102+
$returnValue = Cli::RETURN_FAILURE;
103103
} catch (\Exception $e) {
104104
$output->writeln('process unknown error:');
105105
$output->writeln($e->getMessage());
106106

107107
$output->writeln($e->getTraceAsString(), OutputInterface::VERBOSITY_DEBUG);
108+
$returnValue = Cli::RETURN_FAILURE;
108109
}
109110
}
110111

dev/tests/integration/testsuite/Magento/Indexer/Console/Command/IndexerReindexCommandTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\Indexer\Console\Command;
99

10+
use Magento\Framework\Console\Cli;
1011
use Magento\Framework\ObjectManagerInterface;
1112
use Magento\TestFramework\Helper\Bootstrap;
1213
use PHPUnit\Framework\MockObject\MockObject as Mock;
14+
use PHPUnit\Framework\TestCase;
1315
use Symfony\Component\Console\Input\InputInterface;
1416
use Symfony\Component\Console\Output\OutputInterface;
1517

@@ -19,7 +21,7 @@
1921
* @magentoDbIsolation disabled
2022
* @magentoAppIsolation enabled
2123
*/
22-
class IndexerReindexCommandTest extends \PHPUnit\Framework\TestCase
24+
class IndexerReindexCommandTest extends TestCase
2325
{
2426
/**
2527
* @var ObjectManagerInterface
@@ -56,14 +58,23 @@ protected function setUp(): void
5658

5759
/**
5860
* @magentoDataFixture Magento/Store/_files/second_store_group_with_second_website.php
61+
* @return void
5962
*/
60-
public function testReindexAll()
63+
public function testReindexAll(): void
6164
{
6265
$status = $this->command->run($this->inputMock, $this->outputMock);
63-
$this->assertEquals(
64-
\Magento\Framework\Console\Cli::RETURN_SUCCESS,
65-
$status,
66-
'Index wasn\'t success'
67-
);
66+
$this->assertEquals(Cli::RETURN_SUCCESS, $status, 'Index wasn\'t success');
67+
}
68+
69+
/**
70+
* Check that 'indexer:reindex' command return right code.
71+
*
72+
* @magentoDataFixture Magento/Indexer/_files/wrong_config_data.php
73+
* @return void
74+
*/
75+
public function testReindexAllWhenSomethingIsWrong(): void
76+
{
77+
$status = $this->command->run($this->inputMock, $this->outputMock);
78+
$this->assertEquals(Cli::RETURN_FAILURE, $status, 'Index didn\'t return failure code');
6879
}
6980
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Config\Model\Config\Factory;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/** @var Factory $configFactory */
12+
$configFactory = Bootstrap::getObjectManager()->get(Factory::class);
13+
$config = $configFactory->create();
14+
$config->setScope('stores');
15+
$config->setDataByPath('catalog/search/elasticsearch7_server_port', 2309);
16+
$config->save();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\App\ResourceConnection;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/** @var ResourceConnection $resource */
12+
$resource = Bootstrap::getObjectManager()->get(ResourceConnection::class);
13+
$connection = $resource->getConnection();
14+
$tableName = $resource->getTableName('core_config_data');
15+
16+
$connection->query("DELETE FROM $tableName WHERE path = 'catalog/search/elasticsearch7_server_port'"
17+
." AND scope = 'stores';");

0 commit comments

Comments
 (0)