77
88namespace Magento \Framework \Console ;
99
10+ use Magento \Framework \App \Filesystem \DirectoryList ;
11+ use Magento \Framework \App \ObjectManager ;
1012use Magento \Framework \App \State ;
1113use PHPUnit \Framework \TestCase ;
1214
@@ -67,14 +69,43 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
6769 $ _SERVER ['argv ' ] = $ testArgv ;
6870
6971 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+ }
7284
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 ();
78109
79110 // Get the State object from the ObjectManager
80111 $ state = $ objectManager ->get (State::class);
@@ -85,6 +116,22 @@ public function testStateGetModeWithMagentoInitParams(string $mode)
85116 $ state ->getMode (),
86117 'State::getMode() should return " ' . $ mode . '" when MAGE_MODE set via --magento-init-params '
87118 );
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+ );
88135 } catch (\Exception $ e ) {
89136 }
90137 }
@@ -102,4 +149,21 @@ public static function modeDataProvider(): array
102149 ['default ' ]
103150 ];
104151 }
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+ }
105169}
0 commit comments