コード例 #1
0
/**
 * @param $strTestFile         - the file to check for test-cases
 * @param $arrDefinedFunctions - all user-definied functions until now
 * @param $intParentPID        - the process-pid of the parent
 * 
 * @throw \Exception - if first parameter is not a string
 * @throw \Exception - if given file is not a file nor readable
 * @throw \Exception - if given parent-id is not an integer
 *
 * create a closure for execution in a fork. it will: 
 * - include the given test-file
 * - find test-cases definied in test-file
 * - send list of test-cases to queue
 * - send SIGTERM to parent id and exit
 *
 **/
function getTestCaseClosure($strTestFile, array $arrDefinedFunctions, $intParentPID)
{
    if (!is_string($strTestFile)) {
        throw new \Exception("first given parameter is not a string");
    }
    if (!is_file($strTestFile) || !is_readable($strTestFile)) {
        throw new \Exception("given file is not a file or not readable: {$strTestFile}");
    }
    if (!is_int($intParentPID)) {
        throw new \Exception("third given parameter is not an integer");
    }
    return function () use($strTestFile, $arrDefinedFunctions, $intParentPID) {
        include $strTestFile;
        # get test-cases
        $arrAllFunctions = get_defined_functions();
        $arrUserFunctions = $arrAllFunctions['user'];
        $arrDefinedFunctions = array_diff($arrUserFunctions, $arrDefinedFunctions);
        $arrTestCases = array();
        foreach ($arrDefinedFunctions as $strFunction) {
            if (fnmatch('aphpunit\\testcases\\test*', $strFunction, FNM_NOESCAPE)) {
                $arrTestCases[] = $strFunction;
            }
        }
        # collect all information in this structure
        $arrMsgContent = array('file' => $strTestFile, 'functions' => $arrTestCases);
        # send the result to the queue
        $objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
        $objQueue->send(serialize($arrMsgContent));
        # kill thread after sending parent a SIGTERM
        posix_kill($intParentPID, SIGTERM);
        exit;
    };
}
コード例 #2
0
ファイル: Assertions.inc.php プロジェクト: t-zuehlsdorff/asap
/**
 * @param $cloThrower           - closure which should throw an exception
 * @param $strExpectedException - the expected exception
 *
 * check if the $cloThrower throws the expected exception
 * if an unexpected exception is thrown, it will be also catched,
 * to allow further execution of the test-case.
 *
 * the assertion environment will additionally contains:
 * - exception_uncatched
 * - exception_expected
 * - exception_thrown
 *
 * the result of the test ist send to the queue
 *
 **/
function expectException($cloThrower, $strExpectedException)
{
    $arrEnv = getAssertionEnvironment();
    $arrEnv['exception_expected'] = $strExpectedException;
    try {
        $cloCatcher = create_function('$cloThrower', 'try { $cloThrower(); return false; } 
                                    catch (' . $strExpectedException . ' $objException) { return true; }');
        $arrEnv['success'] = $cloCatcher($cloThrower);
        $arrEnv['exception_thrown'] = $strExpectedException;
    } catch (\Exception $objException) {
        $arrEnv['success'] = false;
        $arrEnv['exception_uncatched'] = get_class($objException);
    }
    $objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
    $objQueue->send(serialize($arrEnv));
}
コード例 #3
0
ファイル: aphpunit.php プロジェクト: t-zuehlsdorff/asap
require_once __DIR__ . '/inc/TestResultPrinting.inc.php';
######################################
# check given parameter for test-run #
######################################
if (empty($argv[1])) {
    die("no directory with testcases given\n");
}
$strTestDir = $argv[1];
if (!is_dir($strTestDir)) {
    die("given path is not a directory: {$strTestDir}\n");
}
#########################
# initialize ipc-queues #
#########################
# initialize ipc-queue empty, to avoid messages from old test-cases
$objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
$objQueue->clear();
#################################
# initialize forking-management #
#################################
$objFork = new \Fork();
$objFork->setMaxForks(MAX_FORKS);
####################################
# initialize runtime-configuration #
####################################
# get id of the process - it will be the parent of all forked childs
$intParentPID = posix_getppid();
# get a list of all user-definied functions until here
# we can skip them when looking for newly definied test-cases
$arrAllFunctions = get_defined_functions();
$arrDefinedFunctions = $arrAllFunctions['user'];