@@ -382,26 +382,50 @@ class Tester
382
382
* @return null|array
383
383
* @throws \Exception
384
384
*/
385
- public function testConfig ($ silent = false )
385
+ public function testConfig ($ silent = false , array | string | null $ expectedPattern = null ): ? array
386
386
{
387
387
$ configFile = $ this ->createConfig ();
388
388
$ cmd = self ::findExecutable () . ' -n -tt -y ' . $ configFile . ' 2>&1 ' ;
389
389
$ this ->trace ('Testing config using command ' , $ cmd , true );
390
390
exec ($ cmd , $ output , $ code );
391
+ $ found = 0 ;
392
+ if ($ expectedPattern !== null ) {
393
+ $ expectedPatterns = is_array ($ expectedPattern ) ? $ expectedPattern : [$ expectedPattern ];
394
+ }
391
395
if ($ code ) {
392
396
$ messages = [];
393
397
foreach ($ output as $ outputLine ) {
394
398
$ message = preg_replace ("/\[.+?\]/ " , "" , $ outputLine , 1 );
399
+ if ($ expectedPattern !== null ) {
400
+ for ($ i = 0 ; $ i < count ($ expectedPatterns ); $ i ++) {
401
+ $ pattern = $ expectedPatterns [$ i ];
402
+ if ($ pattern !== null && preg_match ($ pattern , $ message )) {
403
+ $ found ++;
404
+ $ expectedPatterns [$ i ] = null ;
405
+ }
406
+ }
407
+ }
395
408
$ messages [] = $ message ;
396
409
if ( ! $ silent ) {
397
410
$ this ->error ($ message , null , false );
398
411
}
399
412
}
413
+ } else {
414
+ $ messages = null ;
415
+ }
400
416
401
- return $ messages ;
417
+ if ($ expectedPattern !== null && $ found < count ($ expectedPatterns )) {
418
+ $ missingPatterns = array_filter ($ expectedPatterns );
419
+ $ errorMessage = sprintf (
420
+ "The expected config %s %s %s not been found " ,
421
+ count ($ missingPatterns ) > 1 ? 'patterns ' : 'pattern ' ,
422
+ implode (', ' , $ missingPatterns ),
423
+ count ($ missingPatterns ) > 1 ? 'have ' : 'has ' ,
424
+ );
425
+ $ this ->error ($ errorMessage );
402
426
}
403
427
404
- return null ;
428
+ return $ messages ;
405
429
}
406
430
407
431
/**
@@ -1155,9 +1179,19 @@ class Tester
1155
1179
return $ address ;
1156
1180
}
1157
1181
1158
- return sys_get_temp_dir () . '/ ' .
1159
- hash ('crc32 ' , dirname ($ address )) . '- ' .
1160
- basename ($ address );
1182
+ $ addressPart = hash ('crc32 ' , dirname ($ address )) . '- ' . basename ($ address );
1183
+
1184
+ // is longer on Mac, than on Linux
1185
+ $ tmpDirAddress = sys_get_temp_dir () . '/ ' . $ addressPart ;
1186
+ ;
1187
+
1188
+ if (strlen ($ tmpDirAddress ) <= 104 ) {
1189
+ return $ tmpDirAddress ;
1190
+ }
1191
+
1192
+ $ srcRootAddress = dirname (__DIR__ , 3 ) . '/ ' . $ addressPart ;
1193
+
1194
+ return $ srcRootAddress ;
1161
1195
}
1162
1196
1163
1197
return $ this ->getHost ($ type ) . ': ' . $ port ;
0 commit comments