#!/usr/bin/env 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('5.6.0', PHP_VERSION, '>')) {
    fwrite(
        STDERR,
        sprintf(
            'This version of PHPUnit is supported on PHP 5.6, PHP 7.0, and PHP 7.1.' . 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');
}

// Ensure correct include_path for RHSCL
$inc = get_include_path();
$dirs = explode(':', $inc);
if (!in_array('/usr/share/php', $dirs)) {
    $dirs[] = '/usr/share/php';
    set_include_path(implode(':', $dirs));
}
unset ($inc, $dirs);

// 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', stream_resolve_include_path('PHPUnit/Autoload.php'));
}

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
}
