function run($reporter)
 {
     $context = SimpleTest::getContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->reporter = $reporter;
     $this->reporter->paintCaseStart($this->getLabel());
     if ($this->needPDO) {
         $this->reporter->makeDry(!$this->assertTrue(class_exists('PDO', false), 'PDO does not exists ! You should install PDO because tests need it.'));
     }
     $this->setUpRun();
     foreach ($this->getTests() as $method) {
         if ($this->reporter->shouldInvoke($this->getLabel(), $method)) {
             $this->skip();
             if ($this->shouldSkip()) {
                 break;
             }
             $invoker = $this->reporter->createInvoker($this->createInvoker());
             $invoker->before($method);
             $invoker->invoke($method);
             $invoker->after($method);
         }
     }
     $this->tearDownRun();
     $this->reporter->paintCaseEnd($this->getLabel());
     unset($this->reporter);
     return $reporter->getStatus();
 }
Exemplo n.º 2
0
/**
 *    Checks the current test context to see if a test has
 *    ever been run.
 *    @return boolean        True if tests have run.
 */
function tests_have_run()
{
    if ($context = SimpleTest::getContext()) {
        return (bool) $context->getTest();
    }
    return false;
}
Exemplo n.º 3
0
 /**
  *    Wires up the error queue for a single test.
  *    @return SimpleErrorQueue    Queue connected to the test.
  *    @access private
  */
 protected function createErrorQueue()
 {
     $context = SimpleTest::getContext();
     $test = $this->getTestCase();
     $queue = $context->get('SimpleErrorQueue');
     $queue->setTestCase($test);
     return $queue;
 }
Exemplo n.º 4
0
 /**
  * @param string $testName
  */
 protected function shouldPaintMethod($testName)
 {
     $testCase = SimpleTest::getContext()->getTest();
     if (!$testCase instanceof CakeTestCase) {
         return true;
     }
     return !in_array(strtolower($testName), $testCase->methods);
 }
 /**
  * @param string $testCase
  * @param string $method
  * @return boolean
  */
 public function shouldInvoke($testCase, $method)
 {
     $test = SimpleTest::getContext()->getTest();
     if ($test instanceof CakeTestCase && in_array(strtolower($method), $test->methods)) {
         return true;
     }
     return parent::shouldInvoke($testCase, $method);
 }
Exemplo n.º 6
0
 /**
  *    Wires up the error queue for a single test.
  *
  *    @return SimpleErrorQueue    Queue connected to the test.
  */
 public function &_createErrorQueue()
 {
     $context =& SimpleTest::getContext();
     $test =& $this->getTestCase();
     $queue =& $context->get('SimpleErrorQueue');
     $queue->setTestCase($test);
     return $queue;
 }
Exemplo n.º 7
0
 /**
  *    Invokes a test method and dispatches any
  *    untrapped errors. Called back from
  *    the visiting runner.
  *    @param string $method    Test method to call.
  *    @access public
  */
 function invoke($method)
 {
     $context =& SimpleTest::getContext();
     $queue =& $context->get('SimpleErrorQueue');
     $queue->setTestCase($this->GetTestCase());
     set_error_handler('SimpleTestErrorHandler');
     parent::invoke($method);
     while (list($severity, $message, $file, $line) = $queue->extract()) {
         $severity = SimpleErrorQueue::getSeverityAsString($severity);
         $test =& $this->getTestCase();
         $test->error($severity, $message, $file, $line);
     }
     restore_error_handler();
 }
Exemplo n.º 8
0
 /**
  *    Lists rather then invokes a test method. Consequently,
  *    we do not invoke the setUp() and tearDown() calls either.
  *    @param string $method    Test method to call.
  *    @access public
  */
 function invoke($method)
 {
     $context = SimpleTest::getContext();
     $test = $this->getTestCase();
     // $context->getTest();
     $reporter = $context->getReporter();
     // use 'user signal' as the way to render the list entry:
     $case = get_class($test);
     if ($case != $test->getLabel()) {
         $case = sprintf("%s [%s]", $case, $test->getLabel());
     }
     $show_breadcrumb = $reporter->includeBreadCrumb(false);
     $reporter->paintSignal("Test", sprintf("Case: %s | Method: %s", $case, $method));
     $reporter->includeBreadCrumb($show_breadcrumb);
 }
Exemplo n.º 9
0
 /**
  *    Invokes a test method whilst trapping expected
  *    exceptions. Any left over unthrown exceptions
  *    are then reported as failures.
  *    @param string $method    Test method to call.
  */
 function invoke($method)
 {
     $trap = SimpleTest::getContext()->get('SimpleExceptionTrap');
     $trap->clear();
     try {
         parent::invoke($method);
     } catch (Exception $exception) {
         if (!$trap->isExpected($this->getTestCase(), $exception)) {
             $this->getTestCase()->exception($exception);
         }
         $trap->clear();
     }
     if ($message = $trap->getOutstanding()) {
         $this->getTestCase()->fail($message);
     }
 }
Exemplo n.º 10
0
 public function send($v1, $v2)
 {
     // test for context
     $context = SimpleTest::getContext();
     $test = $context->getTest();
     $mock = $this->mock;
     foreach ($this->_expected_context as $key => $value) {
         $test->assertEqual($value, $this->_context->get($key));
     }
     $step = $mock->getCallCount('send');
     if (isset($this->_expected_context_at[$step])) {
         foreach ($this->_expected_context_at[$step] as $key => $value) {
             $test->assertEqual($value, $this->_context->get($key));
         }
     }
     // boilerplate mock code, does not have return value or references
     $args = func_get_args();
     $mock->invoke('send', $args);
 }
Exemplo n.º 11
0
 /**
  *    Invokes a test method whilst trapping expected
  *    exceptions. Any left over unthrown exceptions
  *    are then reported as failures.
  *
  *    @param string $method    Test method to call.
  */
 public function invoke($method)
 {
     $trap = SimpleTest::getContext()->get('SimpleExceptionTrap');
     $trap->clear();
     try {
         $has_thrown = false;
         parent::invoke($method);
     } catch (Exception $exception) {
         $has_thrown = true;
         if (!$trap->isExpected($this->getTestCase(), $exception)) {
             $this->getTestCase()->exception($exception);
         }
         $trap->clear();
     }
     if ($message = $trap->getOutstanding()) {
         $this->getTestCase()->fail($message);
     }
     if ($has_thrown) {
         try {
             parent::getTestCase()->tearDown();
         } catch (Exception $e) {
         }
     }
 }
Exemplo n.º 12
0
 public function testQueueStartsEmpty()
 {
     $context = SimpleTest::getContext();
     $queue = $context->get('SimpleErrorQueue');
     $this->assertFalse($queue->extract());
 }
Exemplo n.º 13
0
 /**
  *    Finds currently running test.
  *    @return SimpeTestCase    Current test case.
  *    @access protected
  */
 function _getCurrentTestCase()
 {
     $context =& SimpleTest::getContext();
     return $context->getTest();
 }
Exemplo n.º 14
0
 /**
  *    Finds currently running test.
  *    @return SimpeTestCase    Current test case.
  */
 protected function getCurrentTestCase()
 {
     return SimpleTest::getContext()->getTest();
 }
 /**
  * @param string $testName
  */
 public function paintMethodStart($testName)
 {
     parent::paintMethodStart($testName);
     $this->xmlWriter->startTestCase($testName, SimpleTest::getContext()->getTest());
     $this->methodStartTime = microtime(true);
     $this->assertionCount = 0;
 }
Exemplo n.º 16
0
    /**
     *    Uses reflection to run every method within itself
     *    starting with the string "test" unless a method
     *    is specified.
     *    @param SimpleReporter $reporter    Current test reporter.
     *    @return boolean                    True if all tests passed.
     *    @access public
     */
    function run(&$reporter) {
        $context = &SimpleTest::getContext();
        $context->setTest($this);
        $context->setReporter($reporter);
        $this->_reporter = &$reporter;
        $started = false;
        foreach ($this->getTests() as $method) {
            if ($reporter->shouldInvoke($this->getLabel(), $method)) {
                $this->skip();
                if ($this->_should_skip) {
                    break;
                }
                if (! $started) {
                    $reporter->paintCaseStart($this->getLabel());
                    $started = true;
                }
//moodlefix begins
                if (defined('TIME_ALLOWED_PER_UNIT_TEST')) {
                    set_time_limit(TIME_ALLOWED_PER_UNIT_TEST);
                }
//moodlefix ends
                $invoker = &$this->_reporter->createInvoker($this->createInvoker());
                $invoker->before($method);
                $invoker->invoke($method);
                $invoker->after($method);
            }
        }
        if ($started) {
            $reporter->paintCaseEnd($this->getLabel());
        }
        unset($this->_reporter);
//moodlefix begins
        $context->unsetTest();
//moodlefix ends
        return $reporter->getStatus();
    }
Exemplo n.º 17
0
 /**
  * @param string $text
  * @param string $type
  * @param string $file
  * @param string $line
  * @param string $message
  * @param string $failureOrError
  * @since Method available since Release 2.17.0
  */
 protected function writeFailureOrError($text, $type, $file, $line, $message, $failureOrError)
 {
     $methodIsArtificial = false;
     if (!$this->methodStarted) {
         if (\SimpleTest::getContext()->getTest()->_should_skip) {
             $testName = 'skip';
         } else {
             $testName = 'ARTIFICIAL';
         }
         $this->paintMethodStart($testName);
         $methodIsArtificial = true;
     }
     $this->junitXMLWriter->{'write' . $failureOrError}($text, $type, $file, $line, $message);
     if ($methodIsArtificial) {
         $this->paintMethodEnd($testName);
     }
 }
Exemplo n.º 18
0
 public function run($reporter)
 {
     $context = SimpleTest::getContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->reporter = $reporter;
     $started = false;
     foreach ($this->specs as $spec) {
         foreach ($spec["tests"] as $test) {
             $method = $test["method_name"];
             if ($reporter->shouldInvoke($spec["name"], $method)) {
                 if (!$started) {
                     $reporter->paintCaseStart($this->getLabel());
                     $started = true;
                 }
                 $invoker = $this->reporter->createInvoker($this->createInvoker());
                 $invoker->before($method);
                 $invoker->invoke($method);
                 $invoker->after($method);
             }
         }
     }
     if ($started) {
         $reporter->paintCaseEnd($this->getLabel());
     }
     unset($this->reporter);
     $context->setTest(null);
     return $reporter->getStatus();
 }
Exemplo n.º 19
0
 function &_getCurrentTestCase()
 {
     $context =& SimpleTest::getContext();
     $test =& $context->getTest();
     return $test->test;
 }
Exemplo n.º 20
0
 /**
  *    Uses reflection to run every method within itself
  *    starting with the string "test" unless a method
  *    is specified.
  *    @param SimpleReporter $reporter    Current test reporter.
  *    @return boolean                    True if all tests passed.
  *    @access public
  */
 function run(&$reporter) {
     $context = &SimpleTest::getContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->_reporter = &$reporter;
     $started = false;
     foreach ($this->getTests() as $method) {
         if(getenv('TEST_METHOD') !== false && $method != getenv('TEST_METHOD')) {
             continue;
         } else if (getenv('TEST_METHOD')!==false) {
             echo "Running Single Test: $method\n";
         }
         if ($reporter->shouldInvoke($this->getLabel(), $method)) {
             $this->skip();
             if ($this->_should_skip) {
                 break;
             }
             if (! $started) {
                 $reporter->paintCaseStart($this->getLabel());
                 $started = true;
             }
             $invoker = &$this->_reporter->createInvoker($this->createInvoker());
             $invoker->before($method);
             $invoker->invoke($method);
             $invoker->after($method);
         }
     }
     if ($started) {
         $reporter->paintCaseEnd($this->getLabel());
     }
     unset($this->_reporter);
     return $reporter->getStatus();
 }
Exemplo n.º 21
0
 protected function _extractExceptionFileAndLine($e)
 {
     $context = SimpleTest::getContext();
     if (!is_object($context)) {
         return '???:???';
     }
     $ref = new ReflectionClass($context->getTest());
     $test_file = $ref->getFileName();
     if ($e->getFile() == $test_file) {
         return $e->getFile() . ':' . $e->getLine();
     }
     foreach ($e->getTrace() as $item) {
         if ($item['file'] == $test_file) {
             return $item['file'] . ':' . $item['line'];
         }
     }
     return '???:???';
 }
Exemplo n.º 22
0
 /**
  *    Uses reflection to run every method within itself
  *    starting with the string "test" unless a method
  *    is specified.
  *    @param SimpleReporter $reporter    Current test reporter.
  *    @return boolean                    True if all tests passed.
  *    @access public
  */
 function run(&$reporter)
 {
     $context =& SimpleTest::getContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->_reporter =& $reporter;
     $reporter->paintCaseStart($this->getLabel());
     $this->skip();
     if (!$this->_should_skip) {
         foreach ($this->getTests() as $method) {
             if ($reporter->shouldInvoke($this->getLabel(), $method)) {
                 $invoker =& $this->_reporter->createInvoker($this->createInvoker());
                 $invoker->before($method);
                 $invoker->invoke($method);
                 $invoker->after($method);
             }
         }
     }
     $reporter->paintCaseEnd($this->getLabel());
     unset($this->_reporter);
     return $reporter->getStatus();
 }
Exemplo n.º 23
0
 /**
  *    Tells SimpleTest to ignore an upcoming exception as not relevant
  *    to the current test. It doesn't affect the test, whether thrown or
  *    not.
  *    @param SimpleExpectation/Exception $ignored  The error to ignore.
  *    @access public
  */
 public function ignoreException($ignored = false)
 {
     SimpleTest::getContext()->get('SimpleExceptionTrap')->ignoreException($ignored);
 }
Exemplo n.º 24
0
 function testContextHoldsCurrentTestCase()
 {
     $context =& SimpleTest::getContext();
     $this->assertReference($this, $context->getTest());
 }
Exemplo n.º 25
0
 /**
  *    Uses reflection to run every method within itself
  *    starting with the string "test" unless a method
  *    is specified.
  * @param SimpleReporter $reporter Current test reporter.
  * @return bool                    True if all tests passed.
  */
 public function run($reporter)
 {
     $context = SimpleTest::getContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->reporter = $reporter;
     $started = false;
     foreach ($this->getTests() as $method) {
         if ($reporter->shouldInvoke($this->getLabel(), $method)) {
             $this->skip();
             if ($this->should_skip) {
                 break;
             }
             if (!$started) {
                 $reporter->paintCaseStart($this->getLabel());
                 $started = true;
             }
             $invoker = $this->reporter->createInvoker($this->createInvoker());
             $invoker->before($method);
             $invoker->invoke($method);
             $invoker->after($method);
         }
     }
     if ($started) {
         $reporter->paintCaseEnd($this->getLabel());
     }
     unset($this->reporter);
     $context->setTest(null);
     return $reporter->getStatus();
 }
Exemplo n.º 26
0
 /**
  *    Prepares for an exception. If the error mismatches it
  *    passes through, otherwise it is swallowed. Any
  *    left over errors trigger failures.
  *    @param SimpleExpectation/Exception $expected  The error to match.
  *    @param string $message                        Message on failure.
  *    @access public
  */
 function expectException($expected = false, $message = '%s')
 {
     $queue = SimpleTest::getContext()->get('SimpleExceptionTrap');
     $line = $this->getAssertionLine();
     $queue->expectException($expected, $message . $line);
 }
Exemplo n.º 27
0
 /**
  *    Prepares for an exception. If the error mismatches it
  *    passes through, otherwise it is swallowed. Any
  *    left over errors trigger failures.
  *    @param SimpleExpectation/Exception $expected  The error to match.
  *    @param string $message                        Message on failure.
  *    @access public
  */
 function expectException($expected = false, $message = '%s')
 {
     $context =& SimpleTest::getContext();
     $queue =& $context->get('SimpleExceptionTrap');
     // :HACK: Directly substituting in seems to cause a segfault with
     // Zend Optimizer on some systems
     $line = $this->getAssertionLine();
     $queue->expectException($expected, $message . $line);
 }
Exemplo n.º 28
0
 public function testContextHoldsCurrentTestCase()
 {
     $context = SimpleTest::getContext();
     $this->assertSame($this, $context->getTest());
 }
Exemplo n.º 29
0
 function testTrappedErrorPlacedInQueue()
 {
     trigger_error('Ouch!');
     $context =& SimpleTest::getContext();
     $queue =& $context->get('SimpleErrorQueue');
     list($severity, $message, $file, $line) = $queue->extract();
     $this->assertEqual($message, 'Ouch!');
     $this->assertEqual($file, __FILE__);
     $this->assertFalse($queue->extract());
 }
Exemplo n.º 30
0
/**
 * Dumps error queue, useful if there has been a fatal error.
 */
function htmlpurifier_dump_error_queue()
{
    $context = SimpleTest::getContext();
    $queue = $context->get('SimpleErrorQueue');
    while (($error = $queue->extract()) !== false) {
        var_dump($error);
    }
}