X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FRandomImageGenerator.php;h=41cd039d3da51b49be5bd21d3f5c54e29cd62bff;hb=0f24b13ea03a7226bd7b9f0d84f4deee8bea0736;hp=7fd5f1dd38cbfe2984581f9414d51d9ef8317b59;hpb=f459a71f75941a83335d6d63ee12079a4b586793;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php b/tests/phpunit/includes/api/RandomImageGenerator.php index 7fd5f1dd38..41cd039d3d 100644 --- a/tests/phpunit/includes/api/RandomImageGenerator.php +++ b/tests/phpunit/includes/api/RandomImageGenerator.php @@ -23,6 +23,8 @@ * @author Neil Kandalgaonkar */ +use MediaWiki\Shell\Shell; + /** * RandomImageGenerator: does what it says on the tin. * Can fetch a random image, or also write a number of them to disk with random filenames. @@ -105,7 +107,7 @@ class RandomImageGenerator { * * @param int $number Number of filenames to write * @param string $format Optional, must be understood by ImageMagick, such as 'jpg' or 'gif' - * @param string $dir Directory, optional (will default to current working directory) + * @param string|null $dir Directory, optional (will default to current working directory) * @return array Filenames we just wrote */ function writeImages( $number, $format = 'jpg', $dir = null ) { @@ -310,16 +312,16 @@ class RandomImageGenerator { // for now (only works if you have exiv2 installed, a program to read // and manipulate exif). if ( $wgExiv2Command ) { - $cmd = wfEscapeShellArg( $wgExiv2Command ) - . " -M " - . wfEscapeShellArg( "set Exif.Image.Orientation " . $orientation['exifCode'] ) - . " " - . wfEscapeShellArg( $filename ); - - $retval = 0; - $err = wfShellExec( $cmd, $retval ); + $command = Shell::command( $wgExiv2Command, + '-M', + "set Exif.Image.Orientation {$orientation['exifCode']}", + $filename + )->includeStderr(); + + $result = $command->execute(); + $retval = $result->getExitCode(); if ( $retval !== 0 ) { - print "Error with $cmd: $retval, $err\n"; + print "Error with $command: $retval, {$result->getStdout()}\n"; } } } @@ -396,22 +398,25 @@ class RandomImageGenerator { */ public function writeImageWithCommandLine( $spec, $format, $filename ) { global $wgImageMagickConvertCommand; - $args = []; - $args[] = "-size " . wfEscapeShellArg( $spec['width'] . 'x' . $spec['height'] ); - $args[] = wfEscapeShellArg( "xc:" . $spec['fill'] ); + + $args = [ + $wgImageMagickConvertCommand, + '-size', + $spec['width'] . 'x' . $spec['height'], + "xc:{$spec['fill']}", + ]; foreach ( $spec['draws'] as $draw ) { $fill = $draw['fill']; $polygon = self::shapePointsToString( $draw['shape'] ); $drawCommand = "fill $fill polygon $polygon"; - $args[] = '-draw ' . wfEscapeShellArg( $drawCommand ); + $args[] = '-draw'; + $args[] = $drawCommand; } - $args[] = wfEscapeShellArg( $filename ); + $args[] = $filename; - $command = wfEscapeShellArg( $wgImageMagickConvertCommand ) . " " . implode( " ", $args ); - $retval = null; - wfShellExec( $command, $retval ); + $result = Shell::command( $args )->execute(); - return ( $retval === 0 ); + return ( $result->getExitCode() === 0 ); } /**