Example #1
0
/**
 * @file Bootstrap.php
 *
 * This is an example of bootstrap file that can be used for
 * a PHPUnit test suite using yTest.
 * (see the --bootstrap option of phpunit.php or y_test_runner.php).
 *
 * As ytest relies on autoloading to work, we must define
 * an __autoload function here. You will have to make it suit
 * your own needs too.
 */
function __autoload($class)
{
    /**
     * Start PHP output capture. See comment below.
     */
    if (ob_start() === false) {
        yTest_error('autoload: can\'t start output buffering.');
    }
    /**
     * If the class name starts with yTest_, then it is a yTest file.
     */
    if (substr($class, 0, 6) == 'yTest_') {
        yTest_requireYTestClass($class);
    } elseif (substr($class, 0, 8) == 'PHPUnit_') {
        yTest_requirePhpUnitClass($class);
    } else {
        // TO BE FILLED WITH YOUR OWN __autoload() CODE (if necessary)
        yTest_error('__autoload(): don\'t know how to load ' . $class);
    }
    /** We make sure, using output buffering, that there is no unwanted
     *  output in the loaded classes, which is generally wanted when loading
     *  library PHP files. Of course your need may differ.
     */
    $output = ob_get_clean();
    if ($output === false) {
        yTest_error('autoload: output buffering was not activated ?!?');
    }
    if (strlen($output) > 0) {
        yTest_error('autoload: output detected while loading class ' . $class . ': ' . "\n" . $output . "\n");
    }
}
Example #2
0
 private static function getParamsInfo($methodName, $className)
 {
     $infos = array();
     if ($className === null) {
         $ref = new ReflectionFunction($methodName);
     } else {
         $ref = new ReflectionMethod($className, $methodName);
     }
     foreach ($ref->getParameters() as $param) {
         $pos = $param->getPosition();
         $name = $param->getName();
         $name = trim($name, '"');
         $byRef = $param->isPassedByReference();
         $optional = $param->isOptional();
         if ($optional) {
             if (!$param->isDefaultValueAvailable()) {
                 if ($className !== null) {
                     yTest_error("yTest internal error: yTest_Signature::getParamsInfo() failed to find default parameter value of param '{$name}' of {$className}::{$methodName}");
                 }
                 $defaultVal = null;
             } else {
                 $defaultVal = $param->getDefaultValue();
             }
         } else {
             $defaultVal = null;
         }
         $infos[$pos] = array($name, $byRef, $optional, $defaultVal);
     }
     return $infos;
 }
Example #3
0
 public function undo()
 {
     yTest_Reflection::restoreMethod($this->className, $this->methodName);
     switch ($this->rewireMode) {
         case self::REWIRE_MODE_FOR_ALL_INSTANCES:
             yTest_CallsRouter::$singleton->onUndoClassMethodRewire($this->className, $this->methodName, $this->delegateObject);
             break;
         case self::REWIRE_MODE_FOR_SPECIFIC_INSTANCE:
             yTest_CallsRouter::$singleton->onUndoInstanceMethodRewire($this->instance, $this->methodName, $this->delegateObject);
             break;
         default:
             yTest_error("invalid rewireMode");
             break;
     }
     //yTest_CallsRouter::instance()->dump();
 }
Example #4
0
 public function initialize()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     try {
         $this->deleteAllTables();
     } catch (Exception $ex) {
         yTest_error("yTest_Database::initialize() failed, with exception:", $ex);
     }
 }
Example #5
0
 public function getDelegateObjectForFunction($functionName)
 {
     if (!array_key_exists($functionName, $this->funcNameToDelegate)) {
         yTest_error("getDelegateObjectForFunction() failed for functionName={$functionName}");
     }
     return $this->funcNameToDelegate[$functionName];
 }
Example #6
0
function yTest_checkedPregReplace($pattern, $replace, $subject, $cntExpected)
{
    $subject = preg_replace($pattern, $replace, $subject, -1, $cnt);
    if ($subject === null || $cnt != $cntExpected) {
        yTest_error('Problem on a preg_replace call in bootstrap:', var_export(array('pattern' => $pattern, 'cnt expected' => $cntExpected, 'real cnt' => $cnt, 'subject is null' => is_null($subject)), true));
    }
    return $subject;
}