phptest

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

//three ways to run:
//1. `phptest` system installed
//2. `vendor/bin/phptest` composer installed
//3. `phptest` system install calls `vendor/bin/phptest` composer installed


// if global phptest is called & phptest is also installed to the current package via composer
// then only run the package-level install
$vendor_install = getcwd().'/vendor/bin/phptest';
//vendor_install_2 accounts for the composer update that stopped symlinking & started include-ing the target bin script
$vendor_install2 = getcwd().'/vendor/taeluf/tester/bin/phptest';
if (file_exists($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install2)
){
    $args = array_slice($argv,1);
    $args = array_map(function($v){
        return '"'.addslashes($v).'"';
    }, $args);
    $cmd = "$vendor_install ". implode(' ',$args);
    // because composer started using an include() instead of symlink, the #!/shebang line was occuring before `namespace Composer` & causing errors
    // so now we use `passthru` here to execute the vendor script rather than include it
    passthru($cmd);
    return;
}

// always require() the current package's autoloader
$cwd_autoload = getcwd().'/vendor/autoload.php';
if (!is_file($cwd_autoload)){
    echo "\n\nAutoloader file '$cwd_autoload' not found. "
        ."\n\nphptest must be run from the project root & autoload must be present at vendor/autoload.php"
        ."\n\n";
    return;
}
require($cwd_autoload);

// if global phptest is called & there is NOT a package-level install, then require the global install's autoloader
$global_test_autoload = dirname(__DIR__).'/vendor/autoload.php';
if (is_file($global_test_autoload)&&realpath($cwd_autoload)!=realpath($global_test_autoload)){
    require($global_test_autoload);
}

$dir = getcwd();

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

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

$runner->load_configs($cli, $dir, $cli->args);

$runner->setup_commands($cli);

$cli->load_stdin();

$cli->args = $runner->initialize($cli, $cli->args);

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