phptest

#!/usr/bin/env php
<?php

$tail = 'vendor/taeluf/tester/code/phptest';
if (substr(__FILE__,-strlen($tail))!=$tail
    && file_exists($vendor_phptest=getcwd().'/vendor/bin/phptest')
    // && readline("\nUse vendor/bin/phptest? (y/n):")=='y'
    && realpath($vendor_phptest) != realpath(__FILE__)
){
    echo "\nRunning $vendor_phptest\n";
    $argstring='';
    for ($i=1;$i<count($argv); $i++){
        $argstring.= ' "'.$argv[$i].'"';
    }
    // passthru($vendor_phptest.$argstring);
    require($vendor_phptest);
    return;
}

if (is_file($own_autoloader=__DIR__.'/../vendor/autoload.php')){
    //for running its own tests
    require($own_autoloader);
} else if (is_file($reg_autoloader=__DIR__.'/../autoload.php')){
    // for being run from vendor/bin/phptest
    require($reg_autoloader);
} else if (is_file($ugh_autoloader=dirname(__DIR__,3).'/autoload.php')){
    // for being run from vendor/taeluf/tester/code/phptest
    require($ugh_autoloader);
}
require_once(__DIR__.'/BackwardCompatTester.php');

$dir = getcwd();
if (is_file($autoload=$dir.'/vendor/autoload.php')){
    require_once($autoload);
}

$cli = $runner = new \Tlf\Tester\Runner();

$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/defaults.json'),true));

if (is_file($config=$dir.'/.config/phptest.json')){
    $cli->load_inputs(json_decode(file_get_contents($config),true));
}
if (is_file($config=$dir.'/test/config.json')){
    $cli->load_inputs(json_decode(file_get_contents($config),true));
}


$cli->load_command('main', [$runner, 'run_dir']);
$cli->load_command('init', [$runner, 'init']);
$cli->load_command('server', [$runner, 'start_server']);


$cli->load_stdin();

$runner->backward_compatability();
$runner->execute();