Skip to content

Commit 132b9e6

Browse files
authored
Merge pull request #9899 from magento-gl/spartans_pr_02072025
[Spartans] BugFixes Delivery
2 parents 2a252ae + 9f2f19e commit 132b9e6

File tree

3 files changed

+178
-9
lines changed
  • app/code/Magento/AdminNotification/Controller/Adminhtml/Notification
  • dev/tests/integration/testsuite/Magento/Framework/Console
  • lib/internal/Magento/Framework/Console

3 files changed

+178
-9
lines changed

app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Index.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\AdminNotification\Controller\Adminhtml\Notification;
77

88
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
9+
use Magento\Framework\View\Result\Page;
910

1011
class Index extends \Magento\AdminNotification\Controller\Adminhtml\Notification implements HttpGetActionInterface
1112
{
@@ -14,14 +15,14 @@ class Index extends \Magento\AdminNotification\Controller\Adminhtml\Notification
1415
*/
1516
public function execute()
1617
{
17-
$this->_view->loadLayout();
18-
$this->_setActiveMenu(
19-
'Magento_AdminNotification::system_adminnotification'
20-
)->_addBreadcrumb(
18+
/** @var Page $resultPage */
19+
$resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
20+
$resultPage->setActiveMenu('Magento_AdminNotification::system_adminnotification');
21+
$resultPage->addBreadcrumb(
2122
__('Messages Inbox'),
2223
__('Messages Inbox')
2324
);
24-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Notifications'));
25-
return $this->_view->renderLayout();
25+
$resultPage->getConfig()->getTitle()->prepend(__('Notifications'));
26+
return $resultPage;
2627
}
2728
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe.
4+
* All rights reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Console;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\State;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Integration test for CLI --magento-init-params functionality
17+
*/
18+
class CliStateTest extends TestCase
19+
{
20+
/**
21+
* @var mixed|null
22+
*/
23+
private $originalArgv;
24+
25+
/**
26+
* @inheritDoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
parent::setUp();
31+
32+
// Store original argv
33+
$this->originalArgv = $_SERVER['argv'] ?? null;
34+
}
35+
36+
/**
37+
* @inheritDoc
38+
*/
39+
protected function tearDown(): void
40+
{
41+
// Restore original argv
42+
if ($this->originalArgv !== null) {
43+
$_SERVER['argv'] = $this->originalArgv;
44+
$this->originalArgv = null;
45+
} else {
46+
unset($_SERVER['argv']);
47+
}
48+
49+
parent::tearDown();
50+
}
51+
52+
/**
53+
* Test that State::getMode() when --magento-init-params sets MAGE_MODE
54+
*
55+
* @param string $mode
56+
* @return void
57+
* @dataProvider modeDataProvider
58+
*/
59+
public function testStateGetModeWithMagentoInitParams(string $mode)
60+
{
61+
// Set up test argv with --magento-init-params
62+
$testArgv = [
63+
'php',
64+
'bin/magento',
65+
'setup:upgrade',
66+
'--magento-init-params=MAGE_MODE=' . $mode,
67+
];
68+
$_SERVER['argv'] = $testArgv;
69+
70+
// Get the State object from the ObjectManager
71+
$state = $this->getObjectManager()->get(State::class);
72+
73+
// Assert that State::getMode() returns the correct mode
74+
$this->assertEquals(
75+
$mode,
76+
$state->getMode(),
77+
'State::getMode() should return "' . $mode . '" when MAGE_MODE set via --magento-init-params'
78+
);
79+
}
80+
81+
/**
82+
* Test that multiple --magento-init-params are processed correctly
83+
*
84+
* @return void
85+
*/
86+
public function testMultipleMagentoInitParams()
87+
{
88+
$mode = 'developer';
89+
$cachePath = '/var/tmp/cache';
90+
$varPath = '/var/tmp/var';
91+
92+
// Set up test argv with multiple --magento-init-params
93+
$testArgv = [
94+
'php',
95+
'bin/magento',
96+
'setup:upgrade',
97+
'--magento-init-params=MAGE_MODE=' .$mode .
98+
'&MAGE_DIRS[cache][path]=' . $cachePath . '&MAGE_DIRS[var][path]=' . $varPath,
99+
];
100+
$_SERVER['argv'] = $testArgv;
101+
102+
// Get the ObjectManager
103+
$objectManager = $this->getObjectManager();
104+
105+
// Get the State object from the ObjectManager
106+
$state = $objectManager->get(State::class);
107+
108+
// Assert that State::getMode() returns the correct mode
109+
$this->assertEquals(
110+
$mode,
111+
$state->getMode(),
112+
'State::getMode() should return "' . $mode . '" when MAGE_MODE set via --magento-init-params'
113+
);
114+
115+
// Get the DirectoryList to verify filesystem paths were set
116+
$directoryList = $objectManager->get(DirectoryList::class);
117+
118+
// Assert that custom filesystem paths were applied
119+
$this->assertEquals(
120+
$cachePath,
121+
$directoryList->getPath(DirectoryList::CACHE),
122+
'Custom cache directory path should be set via --magento-init-params'
123+
);
124+
125+
$this->assertEquals(
126+
$varPath,
127+
$directoryList->getPath(DirectoryList::VAR_DIR),
128+
'Custom var directory path should be set via --magento-init-params'
129+
);
130+
}
131+
132+
/**
133+
* Returns magento mode for cli command
134+
*
135+
* @return string[]
136+
*/
137+
public static function modeDataProvider(): array
138+
{
139+
return [
140+
['production'],
141+
['developer'],
142+
['default']
143+
];
144+
}
145+
146+
/**
147+
* Get the ObjectManager from the Cli instance using reflection
148+
*
149+
* @return ObjectManager
150+
*/
151+
private function getObjectManager()
152+
{
153+
// Create a new Cli instance
154+
$cli = new Cli('Magento CLI');
155+
156+
// Get the ObjectManager from the Cli instance using reflection
157+
$reflection = new \ReflectionClass($cli);
158+
$objectManagerProperty = $reflection->getProperty('objectManager');
159+
$objectManagerProperty->setAccessible(true);
160+
return $objectManagerProperty->getValue($cli);
161+
}
162+
}

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\DeploymentConfig;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
1414
use Magento\Framework\App\ProductMetadata;
15+
use Magento\Framework\App\State as AppState;
1516
use Magento\Framework\Composer\ComposerJsonFinder;
1617
use Magento\Framework\Config\ConfigOptionsListConstants;
1718
use Magento\Framework\Console\CommandLoader\Aggregate;
@@ -177,10 +178,15 @@ private function initObjectManager()
177178
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
178179
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
179180
$requestParams = $this->serviceManager->get('magento-init-params');
180-
$appBootstrapKey = Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
181+
$appBootstrapKeys = [
182+
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS,
183+
AppState::PARAM_MODE,
184+
];
181185

182-
if (isset($requestParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) {
183-
$params[$appBootstrapKey] = $requestParams[$appBootstrapKey];
186+
foreach ($appBootstrapKeys as $appBootstrapKey) {
187+
if (isset($requestParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) {
188+
$params[$appBootstrapKey] = $requestParams[$appBootstrapKey];
189+
}
184190
}
185191

186192
$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();

0 commit comments

Comments
 (0)