Skip to content

Commit fedf859

Browse files
committed
AC-13231: Magento option --magento-init-params never used when running cli?
Fix for static test failures
1 parent e2066dc commit fedf859

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

dev/tests/integration/testsuite/Magento/Framework/Console/CliStateTest.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Copyright 2025 Adobe.
44
* All rights reserved.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Console;
89

910
use Magento\Framework\App\State;
10-
use Magento\Framework\Console\Cli;
1111
use PHPUnit\Framework\TestCase;
1212

1313
/**
@@ -17,13 +17,35 @@
1717
class CliStateTest extends TestCase
1818
{
1919
/**
20-
* @var State
20+
* @var mixed|null
2121
*/
22-
private $state;
22+
private $originalArgv;
2323

24+
/**
25+
* @inheritDoc
26+
*/
2427
protected function setUp(): void
2528
{
2629
parent::setUp();
30+
31+
// Store original argv
32+
$this->originalArgv = $_SERVER['argv'] ?? null;
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
protected function tearDown(): void
39+
{
40+
// Restore original argv
41+
if ($this->originalArgv !== null) {
42+
$_SERVER['argv'] = $this->originalArgv;
43+
$this->originalArgv = null;
44+
} else {
45+
unset($_SERVER['argv']);
46+
}
47+
48+
parent::tearDown();
2749
}
2850

2951
/**
@@ -42,15 +64,12 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
4264
'setup:upgrade',
4365
'--magento-init-params=MAGE_MODE=' . $mode,
4466
];
45-
46-
// Store original argv
47-
$originalArgv = $_SERVER['argv'] ?? null;
4867
$_SERVER['argv'] = $testArgv;
4968

5069
try {
5170
// Create a new Cli instance which will use our fixed initObjectManager method
5271
$cli = new Cli('Magento CLI');
53-
72+
5473
// Get the ObjectManager from the Cli instance using reflection
5574
$reflection = new \ReflectionClass($cli);
5675
$objectManagerProperty = $reflection->getProperty('objectManager');
@@ -61,16 +80,12 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
6180
$state = $objectManager->get(State::class);
6281

6382
// Assert that State::getMode() returns the correct mode
64-
$this->assertEquals($mode, $state->getMode(),
65-
'State::getMode() should return "' . $mode . '" when MAGE_MODE=' . $mode . ' is set via --magento-init-params');
66-
67-
} finally {
68-
// Restore original argv
69-
if ($originalArgv !== null) {
70-
$_SERVER['argv'] = $originalArgv;
71-
} else {
72-
unset($_SERVER['argv']);
73-
}
83+
$this->assertEquals(
84+
$mode,
85+
$state->getMode(),
86+
'State::getMode() should return "' . $mode . '" when MAGE_MODE set via --magento-init-params'
87+
);
88+
} catch (\Exception $e) {
7489
}
7590
}
7691

0 commit comments

Comments
 (0)