#!/usr/bin/php
<?php
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

if (version_compare('7.1.0', PHP_VERSION, '>')) {
    fwrite(
        STDERR,
        sprintf(
            'This version of PHPUnit is supported on PHP 7.1, PHP 7.2, and PHP 7.3.' . PHP_EOL .
            'You are using PHP %s (%s).' . PHP_EOL,
            PHP_VERSION,
            PHP_BINARY
        )
    );

    die(1);
}

if (!ini_get('date.timezone')) {
    ini_set('date.timezone', 'UTC');
}

// Libraries PATH
if (file_exists('./vendor/phpunit/phpunit/phpunit') && file_exists('./vendor/autoload.php')) {
    echo "\n==== Redirecting to composer installed version in vendor/phpunit ====\n\n";
    define ('PHPUNIT_COMPOSER_INSTALL', realpath('./vendor/autoload.php'));
} else {
    define ('PHPUNIT_COMPOSER_INSTALL', '/usr/share/php/PHPUnit7/autoload.php');
}

$options = getopt('', array('prepend:'));

if (isset($options['prepend'])) {
    require $options['prepend'];
}

unset($options);

require PHPUNIT_COMPOSER_INSTALL;

if (class_exists('PHPUnit_TextUI_Command')) {
    PHPUnit_TextUI_Command::main(); // PHPUnit v5 or older
} else {
    PHPUnit\TextUI\Command::main(); // PHPUnit v6 or newer
}
