Page_Tester::runTests PHP Method

runTests() public method

public runTests ( $test_obj = null )
    public function runTests($test_obj = null)
    {
        if (!$test_obj) {
            $test_obj = $this;
        }
        $tested = array();
        $data = array();
        foreach (get_class_methods($test_obj) as $method) {
            if (strpos($method, 'test_') === 0) {
                $m = substr($method, 5);
            } elseif (strpos($method, 'prepare_') === 0) {
                $m = substr($method, 8);
            } else {
                continue;
            }
            if (isset($_GET['testonly']) && 'test_' . $_GET['testonly'] != $method) {
                continue;
            }
            // Do not retest same function even if it has both prepare and test
            if ($tested[$m]) {
                continue;
            }
            $tested[$m] = true;
            // Row contains test result data
            $row = array('name' => $m, 'id' => $m);
            foreach ($this->variances as $key => $vari) {
                if (is_numeric($key)) {
                    $key = $vari;
                }
                try {
                    // Input is a result of preparation function
                    if (method_exists($test_obj, 'prepare_' . $m)) {
                        $input = $test_obj->{'prepare_' . $m}($vari, $method);
                    } else {
                        if ($test_obj->hasMethod('prepare')) {
                            $input = $test_obj->prepare($vari, $method);
                        } else {
                            $input = null;
                        }
                    }
                } catch (Exception $e) {
                    if ($e instanceof Exception_SkipTests) {
                        $this->grid->destroy();
                        /** @type View_Error $v_error */
                        $v_error = $this->add('View_Error');
                        $v_error->set('Skipping all tests: ' . $e->getMessage());
                        return;
                    }
                }
                $this->input = $input;
                $test_func = method_exists($test_obj, 'test_' . $m) ? 'test_' . $m : 'test';
                // Test speed
                $me = memory_get_peak_usage();
                $ms = microtime(true);
                $this->cnt = 0;
                declare (ticks=1);
                register_tick_function(array($this, 'ticker'));
                try {
                    //$result=$test_obj->$test_func($input[0],$input[1],$input[2]);
                    $result = $this->executeTest($test_obj, $test_func, $input);
                } catch (Exception $e) {
                    if ($e instanceof Exception_SkipTests) {
                        $this->grid->destroy();
                        /** @type View_Error $v_error */
                        $v_error = $this->add('View_Error');
                        $v_error->set('Skipping all tests: ' . $e->getMessage());
                    }
                    if ($_GET['tester_details'] == $row['name'] && $_GET['vari'] == $vari) {
                        throw $e;
                    }
                    $result = 'Exception: ' . ($e instanceof BaseException ? $e->getText() : $e->getMessage());
                    /** @type P $ll */
                    $ll = $this->add('P', $row['name']);
                    /** @type View $v */
                    $v = $ll->add('View');
                    $v->setElement('a')->setAttr('href', '#')->set('More details')->js('click')->univ()->frameURL('Exception Details for test ' . $row['name'], $this->app->url(null, array('tester_details' => $row['name'], 'vari' => $vari)));
                    $result .= $ll->getHTML();
                }
                $ms = microtime(true) - $ms;
                $me = ($mend = memory_get_peak_usage()) - $me;
                unregister_tick_function(array($this, 'ticker'));
                $row[$key . '_inf'] = 'Ticks: ' . $this->cnt * 1 . '<br/>Memory: ' . $me;
                $result = $this->formatResult($row, $key, $result);
                $k = $key . '_' . $row['name'];
                if ($this->proper_responses[$k] == $result && isset($this->proper_responses[$k])) {
                    $row[$key . '_res'] = '<font color="green">PASS</font><br/>' . htmlspecialchars($result);
                } elseif ($this->proper_responses[$k]) {
                    $row[$key . '_res'] = '<font color="red">' . htmlspecialchars($result) . '</font><br/>' . var_export($this->proper_responses[$k], true);
                }
                $this->responses[] = '"' . $k . '"' . '=>' . var_export($result, true);
            }
            $data[] = $row;
        }
        $this->grid->setSource($data);
    }