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

$autoloadPaths = [__DIR__.'/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
foreach ($autoloadPaths as $autoloadPath) {
    if (file_exists($autoloadPath)) {
        require $autoloadPath;

        break;
    }
}

if(!isset($argv[1]) || !is_dir($argv[1])) {
    die('Usage: api-tester DIRECTORY'.PHP_EOL);
}

use Aa\ApiTester\ApiTest\Runner;
use Aa\ApiTester\ApiTest\SuiteLoader;
use Symfony\Component\Validator\Exception\ValidatorException;

$suiteLoader = new SuiteLoader();
$suite = $suiteLoader->loadFromDir($argv[1]);

$runner = new Runner();
try {
    $runner->run($suite);
    print 'Tests OK'.PHP_EOL.PHP_EOL;
} catch (ValidatorException $exception) {
    print 'Following tests failed:'.PHP_EOL.PHP_EOL;
    print $runner->getLastRunResult();
    exit(1);
}
