7
7
8
8
namespace Magento \Framework \Console ;
9
9
10
+ use Magento \Framework \App \Filesystem \DirectoryList ;
11
+ use Magento \Framework \App \ObjectManager ;
10
12
use Magento \Framework \App \State ;
11
13
use PHPUnit \Framework \TestCase ;
12
14
@@ -67,14 +69,43 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
67
69
$ _SERVER ['argv ' ] = $ testArgv ;
68
70
69
71
try {
70
- // Create a new Cli instance which will use our fixed initObjectManager method
71
- $ cli = new Cli ('Magento CLI ' );
72
+ // Get the State object from the ObjectManager
73
+ $ state = $ this ->getObjectManager ()->get (State::class);
74
+
75
+ // Assert that State::getMode() returns the correct mode
76
+ $ this ->assertEquals (
77
+ $ mode ,
78
+ $ state ->getMode (),
79
+ 'State::getMode() should return " ' . $ mode . '" when MAGE_MODE set via --magento-init-params '
80
+ );
81
+ } catch (\Exception $ e ) {
82
+ }
83
+ }
72
84
73
- // Get the ObjectManager from the Cli instance using reflection
74
- $ reflection = new \ReflectionClass ($ cli );
75
- $ objectManagerProperty = $ reflection ->getProperty ('objectManager ' );
76
- $ objectManagerProperty ->setAccessible (true );
77
- $ objectManager = $ objectManagerProperty ->getValue ($ cli );
85
+ /**
86
+ * Test that multiple --magento-init-params are processed correctly
87
+ *
88
+ * @return void
89
+ */
90
+ public function testMultipleMagentoInitParams ()
91
+ {
92
+ $ mode = 'developer ' ;
93
+ $ cachePath = '/var/tmp/cache ' ;
94
+ $ varPath = '/var/tmp/var ' ;
95
+
96
+ // Set up test argv with multiple --magento-init-params
97
+ $ testArgv = [
98
+ 'php ' ,
99
+ 'bin/magento ' ,
100
+ 'setup:upgrade ' ,
101
+ '--magento-init-params=MAGE_MODE= ' .$ mode .
102
+ '&MAGE_DIRS[cache][path]= ' . $ cachePath . '&MAGE_DIRS[var][path]= ' . $ varPath ,
103
+ ];
104
+ $ _SERVER ['argv ' ] = $ testArgv ;
105
+
106
+ try {
107
+ // Get the ObjectManager
108
+ $ objectManager = $ this ->getObjectManager ();
78
109
79
110
// Get the State object from the ObjectManager
80
111
$ state = $ objectManager ->get (State::class);
@@ -85,6 +116,22 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
85
116
$ state ->getMode (),
86
117
'State::getMode() should return " ' . $ mode . '" when MAGE_MODE set via --magento-init-params '
87
118
);
119
+
120
+ // Get the DirectoryList to verify filesystem paths were set
121
+ $ directoryList = $ objectManager ->get (DirectoryList::class);
122
+
123
+ // Assert that custom filesystem paths were applied
124
+ $ this ->assertEquals (
125
+ $ cachePath ,
126
+ $ directoryList ->getPath (DirectoryList::CACHE ),
127
+ 'Custom cache directory path should be set via --magento-init-params '
128
+ );
129
+
130
+ $ this ->assertEquals (
131
+ $ varPath ,
132
+ $ directoryList ->getPath (DirectoryList::VAR_DIR ),
133
+ 'Custom var directory path should be set via --magento-init-params '
134
+ );
88
135
} catch (\Exception $ e ) {
89
136
}
90
137
}
@@ -102,4 +149,21 @@ public static function modeDataProvider(): array
102
149
['default ' ]
103
150
];
104
151
}
152
+
153
+ /**
154
+ * Get the ObjectManager from the Cli instance using reflection
155
+ *
156
+ * @return ObjectManager
157
+ */
158
+ private function getObjectManager ()
159
+ {
160
+ // Create a new Cli instance
161
+ $ cli = new Cli ('Magento CLI ' );
162
+
163
+ // Get the ObjectManager from the Cli instance using reflection
164
+ $ reflection = new \ReflectionClass ($ cli );
165
+ $ objectManagerProperty = $ reflection ->getProperty ('objectManager ' );
166
+ $ objectManagerProperty ->setAccessible (true );
167
+ return $ objectManagerProperty ->getValue ($ cli );
168
+ }
105
169
}
0 commit comments