#!/usr/bin/env php
<?php
/**
 * Horde Test Runner
 *
 * @category Horde
 * @package  tools
 * @subpackage UnitTests
 * @author   Chuck Hagenbuch <chuck@horde.org>
 * @license  http://www.horde.org/licenses/bsd BSD
 */

/* Stand-in functions if gettext is not available. */
if (!function_exists('_')) {
    function _($string)
    {
        return $string;
    }
}
if (!function_exists('dgettext')) {
    function dgettext($domain, $string)
    {
        return $string;
    }
}
if (!function_exists('ngettext')) {
    function ngettext($msgid1, $msgid2, $n)
    {
        return $n > 1 ? $msgid2 : $msgid1;
    }
}
if (!function_exists('bindtextdomain')) {
    function bindtextdomain()
    {}
}
if (!function_exists('textdomain')) {
    function textdomain()
    {}
}

require_once 'Horde/Test/Autoload.php';
Horde_Test_Autoload::init();

$_SERVER['argv'][] = 'Horde_Test_Runner';
$_SERVER['argv'][] = __FILE__;
PHPUnit_TextUI_Command::main();

/**
 * @category Horde
 * @package  tools
 * @subpackage UnitTests
 * @author   Chuck Hagenbuch <chuck@horde.org>
 * @license  http://www.horde.org/licenses/lgpl21
 */
class Horde_Test_Runner
{
    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('Horde Test Runner');

        $basedir = dirname(__DIR__);

        // Find all AllTests.php files.
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $file) {
            if (!$file->isFile() ||
                $file->getFilename() != 'AllTests.php' ||
                $file->getPathname() == __FILE__ ||
                $file->getPathname() == $basedir . '/Test/lib/Horde/Test/AllTests.php') {
                continue;
            }
            $pathname = $file->getPathname();

            // Include the test suite.
            $suite->addTestSuite(Horde_Test_AllTests::init($pathname)->suite());
        }

        return $suite;
    }
}
