Beispiel #1
0
 public function parse(&$oBase)
 {
     // could be an array of suites, which is fine
     if (is_array($this->m_oSuite)) {
         for ($n = count($this->m_oSuite), $i = 0; $i < $n; $i++) {
             $rs = new APIUnitSuite($this->m_oSuite[$i], $i);
             $rs->parse($oBase);
         }
     } else {
         // validate name and tests
         if (empty($this->m_oSuite->name)) {
             throw new APIUnitException(($this->m_nIndex == -1 ? "Suite" : "Suite[" . $this->m_nIndex . "]") . " has no name");
         }
         $this->Name = $this->m_oSuite->name;
         if (empty($this->m_oSuite->test)) {
             throw new APIUnitException("Suite " . $this->Name . " has no tests");
         }
         // loop and parse tests
         $rt = new APIUnitTest($this->m_oSuite->test);
         // output file
         file_put_contents($oBase->outputdir . "/" . $this->Name . "Test.php", "<?php\n" . "\n" . "require_once('" . $oBase->thisdir . "/APIUnitTester.php');\n" . "\n" . "class " . $this->Name . "Test extends APIUnitTester\n" . "{\n" . $rt->parse($oBase) . "};\n" . "\n" . "?>\n");
     }
 }
Beispiel #2
0
}
// check for input file
if (!file_exists($sInputFile)) {
    die("Input file '{$sInputFile}' does not exist\n");
}
// open and parse file
$oInput = json_decode(file_get_contents($sInputFile));
// validate input
if (empty($oInput)) {
    die("There is a problem with your input file; is it well-formatted JSON?");
}
// could be a suite, an array of suites, a test or an array of tests
$oInput->outputdir = $sOutputDir;
$oInput->thisdir = str_replace("\\", "/", __DIR__);
try {
    if (empty($oInput->suite)) {
        if (empty($oInput->test)) {
            die("There are no tests defined in your input file");
        }
        $rt = new APIUnitTest($oInput->test);
        $sTestCode = $rt->parse($oInput);
        $sFilename = $rt->Name . "Test";
        // output the test file
        file_put_contents($oInput->outputdir . "/" . $rt->Name . "Test.php", "<?php\n" . "\n" . "require_once('" . $oInput->thisdir . "/APIUnitTester.php');\n" . "\n" . "class " . $rt->Name . "Test extends APIUnitTester\n" . "{\n" . $sTestCode . "};\n" . "\n" . "?>");
    } else {
        $rs = new APIUnitSuite($oInput->suite);
        $rs->parse($oInput);
    }
} catch (APIUnitException $ex) {
    die($ex->getMessage());
}