Example #1
0
function __autoload($className)
{
    try {
        $debug = false;
        $slash = SLASH;
        $dirArr = explode($slash, dirname(__FILE__));
        unset($dirArr[count($dirArr) - 1]);
        $lBoxDirName = end($dirArr);
        $projectRootArr = $dirArr;
        unset($projectRootArr[count($projectRootArr) - 1]);
        $projectRootPath = implode($slash, $projectRootArr);
        $paths = array($projectRootPath . $slash . $lBoxDirName, $projectRootPath . $slash . LBOX_DIRNAME_PROJECT, $projectRootPath . $slash . LBOX_DIRNAME_PLUGINS);
        $pathsIgnore = array($projectRootPath . $slash . "{$lBoxDirName}" . $slash . "TAL", $projectRootPath . $slash . "{$lBoxDirName}" . $slash . "dev", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "dev", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "css", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "js", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "documents", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "img", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "filespace", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . ".cache", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . ".tal_compiled", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "wsw");
        $pathsConfig = array($projectRootPath . $slash . "{$lBoxDirName}" . $slash . "config", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "config");
        /*$lime_output	= new lime_output();
        		$lime_output->info('looking for '. $className);*/
        LBoxLoader::getInstance($paths, $pathsIgnore)->debug = $debug ? 'terminal' : false;
        LBoxLoader::getInstance()->load($className);
    } catch (Exception $e) {
        $lime = new lime_output();
        $lime->error($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace());
    }
}
Example #2
0
/**
 * runs all defined tests
 * if tests directory contains coverage folder, it will generate coverage results there
 */
function run_tests()
{
    global $argv;
    // read test directory and run all tests
    $path = dirname(__FILE__) . '/tests';
    $dir = dir($path);
    $lime_output = new lime_output();
    $coverage = $coveragePath = '';
    $tests = array();
    while (($entry = $dir->read()) !== false) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        if (is_dir("{$path}/{$entry}")) {
            if ($entry == 'coverage') {
                $coveragePath = $path . '/' . $entry;
            }
            continue;
        }
        if (is_test($entry)) {
            $tests[getTestNameByPath("{$path}/{$entry}")] = "{$path}/{$entry}";
        }
    }
    // run concrete test
    if (($testName = $argv[1]) && can_param_be_test($testName)) {
        $testName .= 'Test';
        if (!array_key_exists($testName, $tests)) {
            $lime_output->error("cannot find test " . $argv[1] . ' in ' . $path);
            return;
        }
        if ($coveragePath) {
            $coveragePathConcrete = $coveragePath . '/' . $testName;
            LBoxUtil::createDirByPath($coveragePathConcrete);
            $coverage = '--coverage-html ' . $coveragePathConcrete . ' ';
            //$coverage			.=	' --coverage-clover '. $coveragePathConcrete . '/clover.xml ';
        }
        $path = $tests[$testName];
        $call = "phpunit {$coverage} {$path}";
        //$lime_output->info($call);
        $out = getCallReturn($call);
        if (preg_match('/OK \\((\\d+) test(s?)\\, (\\d+) assertion(s?)\\)/', $out, $matchAll)) {
            $lime_output->green_bar($testName);
        } else {
            $lime_output->red_bar($testName);
        }
        echo $out;
        if (strlen($coverage) > 0) {
            if (!doesContainErrorNotification($out)) {
                $lime_output->info("coverage results in {$coveragePath}");
            }
        }
        return;
    }
    // run all loaded tests
    if (count($tests) < 1) {
        $lime_output->comment('no test found in ' . $path);
        return;
    }
    $assertionsCountAtomic = 0;
    $testsCountAtomic = 0;
    foreach ($tests as $name => $path) {
        if ($coveragePath) {
            $coveragePathConcrete = $coveragePath . '/' . $name;
            LBoxUtil::createDirByPath($coveragePathConcrete);
            $coverage = '--coverage-html ' . $coveragePathConcrete . ' ';
            //$coverage			.=	' --coverage-clover '. $coveragePathConcrete . '/clover.xml ';
        }
        $call = "phpunit {$coverage} {$path}";
        //$lime_output->info($call);
        $out = getCallReturn($call);
        $space = '';
        if (preg_match('/OK \\((\\d+) test(s?)\\, (\\d+) assertion(s?)\\)/', $out, $matchAll)) {
            $i = 1;
            foreach ($matchAll as $k => $v) {
                if (is_numeric($v)) {
                    $match[$i] = $v;
                    $i++;
                }
            }
            $assertionsCountAtomic += $match[2];
            $testsCountAtomic += $match[1];
            $outPartName = $name . ' (' . $match[1] . ' tests, ' . $match[2] . ' assertions)';
            for ($i = 0; $i < 68 - strlen($outPartName); $i++) {
                $space .= ' ';
            }
            $lime_output->green_bar($outPartName . $space . 'OK ');
        } else {
            for ($i = 0; $i < 64 - strlen($name); $i++) {
                $space .= ' ';
            }
            $lime_output->red_bar($name . $space . 'FAILED ');
            echo $out;
        }
    }
    $lime_output->echoln("{$testsCountAtomic} tests, {$assertionsCountAtomic} assertions done", array('fg' => 'green'));
    if (strlen($coverage) > 0) {
        if (!doesContainErrorNotification($out)) {
            $lime_output->info("coverage results in {$coveragePath}");
        }
    }
    $dir->close();
}
Example #3
0
 /**
  * checks searched type in cheked files
  * @param string $type
  * @return string
  */
 protected function getPathOfQuickly($type = "", $prefix = NULL)
 {
     $postfix = $this->postfix;
     if ($this->debug == 'terminal') {
         $lime_output = new lime_output();
     }
     if (is_string($prefix)) {
         $fileNameSearch = "{$prefix}.{$type}.{$postfix}";
         if (array_key_exists($fileNameSearch, $this->checkedFiles)) {
             $filePath = $this->checkedFiles[$fileNameSearch];
             if ($this->debug == 'terminal') {
                 $lime_output->echoln("{$type}' found QUICKLY in '{$filePath}", $parameters = array('bg' => 'green', 'fg' => 'white'));
             } else {
                 if ($this->debug) {
                     echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:green;'>'<b>{$type}</b>' found QUICKLY in '<i>{$filePath}</i>'<br /></font>\n";
                 }
             }
             return $filePath;
         } else {
             if ($this->debug == 'terminal') {
                 $lime_output->echoln("'{$type}' NOT found QUICKLY", $parameters = array('bg' => 'red', 'fg' => 'white'));
             } else {
                 if ($this->debug) {
                     echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:red;'>'<b>{$type}</b>' NOT found QUICKLY<br /></font>\n";
                 }
             }
             return "";
         }
     } else {
         foreach ($this->prefixes as $prefix) {
             $fileNameSearch = "{$prefix}.{$type}.{$postfix}";
             if (array_key_exists($fileNameSearch, $this->checkedFiles)) {
                 $filePath = $this->checkedFiles[$fileNameSearch];
                 if ($this->debug == 'terminal') {
                     $lime_output->echoln("'{$type}' found QUICKLY in '{$filePath}", $parameters = array('bg' => 'green', 'fg' => 'white'));
                 } else {
                     if ($this->debug) {
                         echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:green;'>'<b>{$type}</b>' found QUICKLY in '<i>{$filePath}</i>'<br /></font>\n";
                     }
                 }
                 return $filePath;
             }
         }
         if ($this->debug == 'terminal') {
             $lime_output->echoln("'{$type}' NOT found QUICKLY", $parameters = array('bg' => 'red', 'fg' => 'white'));
         } else {
             if ($this->debug) {
                 echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:red;'>'<b>{$type}</b>' NOT found QUICKLY<br /></font>\n";
             }
         }
         return "";
     }
 }