@@ -201,6 +201,25 @@ func merge(a, b map[string]string) map[string]string {
201
201
return merged
202
202
}
203
203
204
+ // checks the context to see if opcache is loaded by default
205
+ // and then handles the PHP modules requests to make sure
206
+ // we don't load opcache.so if it is already loaded by default
207
+ func (t * Test ) HandlePHPModules (php_executable string , ctx * Context ) map [string ]string {
208
+ // two cases:
209
+ // 1. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
210
+ // 2. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
211
+ phpModulesCopy := make (map [string ]string )
212
+ if ctx .OPCacheModuleLoaded [php_executable ] {
213
+ for k , v := range t .PhpModules {
214
+ if ! strings .Contains (v , "opcache.so" ) {
215
+ phpModulesCopy [k ] = v
216
+ }
217
+ }
218
+ }
219
+
220
+ return phpModulesCopy
221
+ }
222
+
204
223
func (t * Test ) MakeRun (ctx * Context ) (Tx , error ) {
205
224
206
225
// we don't support running C tests - assert this so we can
@@ -222,68 +241,22 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) {
222
241
}
223
242
}
224
243
225
- // Make a copy of settings to avoid mutating the original map
226
- // Need to adjust settings to opcache
227
- phpSettings := make (map [string ]string , len (settings ))
228
- setOPCacheEnable := true
229
- setOPCacheEnableCLI := true
230
244
var php_executable string
231
245
if t .IsWeb () {
232
246
php_executable = ctx .CGI
233
- } else {
247
+ } else if t . IsPHP () {
234
248
php_executable = ctx .PHP
235
- }
236
- for k , v := range settings {
237
- phpSettings [k ] = v
238
-
239
- // see if settings affect opcache config
240
- // if so then we will not set config below
241
- if k == "opcache.enable" {
242
- setOPCacheEnable = false
243
- } else if k == "opcache.enable_cli" {
244
- setOPCacheEnableCLI = false
245
- }
246
- }
247
- if ctx .UseOPCache {
248
- if ! ctx .OPCacheModuleLoaded [php_executable ] {
249
- phpSettings ["zend_extension" ] = "opcache.so"
250
- }
251
- if setOPCacheEnable {
252
- phpSettings ["opcache.enable" ] = "1"
253
- }
254
- if setOPCacheEnableCLI {
255
- phpSettings ["opcache.enable_cli" ] = "1"
256
- }
257
249
} else {
258
- if setOPCacheEnable {
259
- phpSettings ["opcache.enable" ] = "0"
260
- }
261
- if setOPCacheEnableCLI {
262
- phpSettings ["opcache.enable_cli" ] = "0"
263
- }
264
- }
265
-
266
- // Make a copy of t.PhpModules and remove any entries containing "opcache.so"
267
- // if opcache.so is loaded by default
268
- //
269
- // two cases:
270
- // 1. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
271
- // 2. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
272
- phpModulesCopy := make (map [string ]string )
273
- if ctx .OPCacheModuleLoaded [php_executable ] {
274
- for k , v := range t .PhpModules {
275
- if ! strings .Contains (v , "opcache.so" ) {
276
- phpModulesCopy [k ] = v
277
- }
278
- }
250
+ return nil , fmt .Errorf ("unknown test type for %s" , t .Path )
279
251
}
280
252
281
- phpSettings = merge (phpSettings , phpModulesCopy )
253
+ phpModulesCopy := t .HandlePHPModules (php_executable , ctx )
254
+ settings = merge (settings , phpModulesCopy )
282
255
283
256
if t .IsWeb () {
284
- return CgiTx (ScriptFile (t .Path ), t .Env , phpSettings , headers , ctx )
257
+ return CgiTx (ScriptFile (t .Path ), t .Env , settings , headers , ctx )
285
258
}
286
- return PhpTx (ScriptFile (t .Path ), t .Env , phpSettings , ctx )
259
+ return PhpTx (ScriptFile (t .Path ), t .Env , settings , ctx )
287
260
}
288
261
289
262
func (t * Test ) MakeSkipIf (ctx * Context ) (Tx , error ) {
@@ -302,6 +275,10 @@ func (t *Test) MakeSkipIf(ctx *Context) (Tx, error) {
302
275
data : t .rawSkipIf ,
303
276
}
304
277
278
+ // handle the PHPMODULES directive
279
+ phpModulesCopy := t .HandlePHPModules (ctx .PHP , ctx )
280
+ settings = merge (settings , phpModulesCopy )
281
+
305
282
return PhpTx (src , t .Env , settings , ctx )
306
283
}
307
284
0 commit comments