php-all-libs/run_tests.php

84 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2022-07-23 03:44:59 +00:00
#!/usr/bin/env php
2022-05-26 03:43:48 +00:00
<?php
use Symfony\Component\Filesystem\Filesystem;
try {
require __DIR__ . '/vendor/autoload.php';
$fs = new Filesystem();
chdir(__DIR__);
$composerJson = json_decode(file_get_contents('composer.json'), true);
$composerLock = json_decode(file_get_contents('composer.lock'), true);
$packageData = array_reduce($composerLock['packages'], function ($pkgs, $p) {
$pkgs[$p['name']] = $p;
return $pkgs;
}, []);
$packages = array_keys($composerJson['require']);
$skip = [
];
$packages = array_diff($packages, $skip);
foreach ($packages as $p) {
chdir(__DIR__);
echo "Testing ", $p, '... ';
$url = $packageData[$p]['source']['url'];
if (is_dir('run_tests/' . $p)) {
chdir('run_tests/' . $p);
run("git pull 2>&1") === 0 || die("git error\n");
echo 'updated... ';
} else {
$fs->mkdir('run_tests/' . $p);
chdir('run_tests/' . $p);
$urlSh = escapeshellarg($url);
run("git clone $urlSh . 2>&1") === 0 || die("git error\n");
echo 'cloned... ';
}
run('composer update --no-interaction 2>&1') === 0 || die("composer error\n");
echo 'installed... ';
$testExec = $p === 'arokettu/is-resource' ? 'tests/tests.sh' : 'vendor/bin/phpunit';
if (!file_exists($testExec)) {
echo 'no tests!', PHP_EOL;
continue;
}
if (run($testExec, $output) === 0) {
echo 'successful!', PHP_EOL;
continue;
}
echo 'failure:', PHP_EOL;
echo implode(PHP_EOL, $output);
die("\n");
}
} catch (Exception $e) {
echo strval($e);
} catch (Throwable $e) {
echo strval($e);
}
function run($command, &$output = null) {
$output = null;
ob_start();
exec($command, $output, $ret);
ob_end_clean();
return $ret;
}