Merge pull request #94 from mlocati/add-extension-specific-tests
Add support for extension-specific testspull/95/head
commit
9159b0aac5
|
@ -5,6 +5,12 @@ $numTestedExtensions = 0;
|
|||
$nameMap = array(
|
||||
'opcache' => 'Zend OPcache',
|
||||
);
|
||||
$testsDir = __DIR__ . '/tests';
|
||||
function runTest($testFile)
|
||||
{
|
||||
return include $testFile;
|
||||
}
|
||||
|
||||
for ($index = 1, $count = isset($argv) ? count($argv) : 0; $index < $count; $index++) {
|
||||
$numTestedExtensions++;
|
||||
$rcThis = 1;
|
||||
|
@ -19,8 +25,24 @@ for ($index = 1, $count = isset($argv) ? count($argv) : 0; $index < $count; $ind
|
|||
if (!extension_loaded($extension)) {
|
||||
fprintf(STDERR, sprintf("Extension not loaded: %s\n", $extension));
|
||||
} else {
|
||||
fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension));
|
||||
$rcThis = 0;
|
||||
$testFile = "${testsDir}/${extension}.php";
|
||||
if (is_file($testFile)) {
|
||||
try {
|
||||
if (runTest($testFile) === true) {
|
||||
fprintf(STDOUT, sprintf("Extension tested successfully: %s\n", $extension));
|
||||
$rcThis = 0;
|
||||
} else {
|
||||
fprintf(STDERR, sprintf("Extension test failed: %s\n", $extension));
|
||||
}
|
||||
} catch (Exception $x) {
|
||||
fprintf(STDERR, sprintf("Extension test failed: %s (%s)\n", $extension, $x->getMessage()));
|
||||
} catch (Throwable $x) {
|
||||
fprintf(STDERR, sprintf("Extension test failed: %s (%s)\n", $extension, $x->getMessage()));
|
||||
}
|
||||
} else {
|
||||
fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension));
|
||||
$rcThis = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($rcThis !== 0) {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
$imageWidth = 8;
|
||||
$imageHeight = 16;
|
||||
$image = imagecreatetruecolor($imageWidth, $imageHeight);
|
||||
$formats = array(
|
||||
'gd2',
|
||||
'gif',
|
||||
'jpeg',
|
||||
'png',
|
||||
'wbmp',
|
||||
'webp',
|
||||
'wbmp',
|
||||
'xbm',
|
||||
'xpm',
|
||||
'gd',
|
||||
);
|
||||
if (PHP_VERSION_ID >= 70200) {
|
||||
$formats = array_merge($formats, array(
|
||||
'bmp',
|
||||
));
|
||||
}
|
||||
$tempFile = null;
|
||||
$image2 = null;
|
||||
try {
|
||||
foreach ($formats as $format) {
|
||||
$loadFuntion = "imagecreatefrom${format}";
|
||||
if (!function_exists($loadFuntion)) {
|
||||
throw new Exception("$loadFuntion() function is missing");
|
||||
}
|
||||
if ($format === 'xpm') {
|
||||
continue;
|
||||
}
|
||||
$saveFuntion = "image${format}";
|
||||
if (!function_exists($saveFuntion)) {
|
||||
throw new Exception("$saveFuntion() function is missing");
|
||||
}
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'dpei');
|
||||
if ($saveFuntion($image, $tempFile) === false) {
|
||||
throw new Exception("$saveFuntion() failed");
|
||||
}
|
||||
if (!is_file($tempFile) || filesize($tempFile) < 1) {
|
||||
throw new Exception("$saveFuntion() created an empty file");
|
||||
}
|
||||
$image2 = $loadFuntion($tempFile);
|
||||
unlink($tempFile);
|
||||
$tempFile = null;
|
||||
if (!is_resource($image2) || imagesx($image2) !== $imageWidth || imagesy($image2) !== $imageHeight) {
|
||||
throw new Exception("$loadFuntion() failed");
|
||||
}
|
||||
imagedestroy($image2);
|
||||
}
|
||||
} finally {
|
||||
imagedestroy($image);
|
||||
if (is_resource($image2)) {
|
||||
imagedestroy($image2);
|
||||
}
|
||||
if($tempFile !== null) {
|
||||
unlink($tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('imagefttext')) {
|
||||
throw new Exception("imagefttext() function is missing");
|
||||
}
|
||||
if (!function_exists('imageantialias')) {
|
||||
throw new Exception("imageantialias() function is missing");
|
||||
}
|
||||
return true;
|
Loading…
Reference in New Issue