9
9
10
10
use Craft ;
11
11
use craft \config \GeneralConfig ;
12
+ use craft \console \Application as ConsoleApplication ;
13
+ use craft \console \Request as ConsoleRequest ;
12
14
use craft \helpers \App ;
13
15
use craft \mail \transportadapters \Sendmail ;
14
16
use craft \models \MailSettings ;
@@ -127,6 +129,19 @@ public function testCliOption(): void
127
129
];
128
130
$ length = count ($ _SERVER ['argv ' ]);
129
131
132
+ // super hacky but no other choice
133
+ $ app = Craft::$ app ;
134
+ Craft::$ app = new ConsoleApplication ([
135
+ 'id ' => $ app ->id ,
136
+ 'basePath ' => $ app ->basePath ,
137
+ 'components ' => [
138
+ 'config ' => fn () => $ app ->getConfig (),
139
+ 'projectConfig ' => fn () => $ app ->getProjectConfig (),
140
+ 'request ' => ConsoleRequest::class,
141
+ 'plugins ' => fn () => $ app ->getPlugins (),
142
+ ],
143
+ ]);
144
+
130
145
self ::assertSame ('foo.sql ' , App::cliOption ('--file-path ' ));
131
146
self ::assertSame ('bar.sql ' , App::cliOption ('-f ' , true ));
132
147
self ::assertSame (true , App::cliOption ('--zip ' ));
@@ -143,6 +158,8 @@ public function testCliOption(): void
143
158
unset($ _SERVER ['argv ' ]);
144
159
}
145
160
161
+ Craft::$ app = $ app ;
162
+
146
163
self ::expectException (InvalidArgumentException::class);
147
164
App::cliOption ('no-dash ' );
148
165
}
0 commit comments