Changeset 740

Show
Ignore:
Timestamp:
06/20/07 16:05:33 (1 year ago)
Author:
mikey
Message:

updated simpletest

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/org/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE

    r172 r740  
    66problems and their fixes... 
    77 
     8Method setWildcard() removed in mocks 
     9------------------------------------- 
     10Even setWildcard() has been removed in 1.0.1beta now. 
     11If you want to test explicitely for a '*' string, then 
     12simply pass in new IdenticalExpectation('*') instead. 
     13 
    814No method _getTest() on mocks 
    915----------------------------- 
    1016This has finally been removed. It was a pretty esoteric 
    1117flex point anyway. It was there to allow the mocks to 
    12 work with other test tools, but no one does this anyway
     18work with other test tools, but no one does this
    1319 
    1420No method assertError(), assertNoErrors(), swallowErrors() 
     
    1622These have been deprecated in 1.0.1beta in favour of 
    1723expectError() and expectException(). assertNoErrors() is 
    18 redundant if you use expectError() as failures are now reporterte
     24redundant if you use expectError() as failures are now reporte
    1925immediately. 
    2026 
  • trunk/src/main/php/org/simpletest/VERSION

    r172 r740  
    1 1.0.1beta 
     11.0.1beta2 
  • trunk/src/main/php/org/simpletest/collector.php

    r172 r740  
    77     * @package SimpleTest 
    88     * @subpackage UnitTester 
    9      * @version $Id: collector.php,v 1.11 2006/11/21 00:26:55 lastcraft Exp $ 
     9     * @version $Id: collector.php,v 1.12 2007/03/27 13:09:35 lastcraft Exp $ 
    1010     */ 
    1111     
     
    4444            if ($handle = opendir($path)) { 
    4545                while (($entry = readdir($handle)) !== false) { 
     46                    if ($this->_isHidden($entry)) { 
     47                        continue; 
     48                    } 
    4649                    $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); 
    4750                } 
     
    6467         */ 
    6568        function _handle(&$test, $file) { 
    66             if (! is_dir($file)) { 
    67                 $test->addTestFile($file)
     69            if (is_dir($file)) { 
     70                return
    6871            } 
     72            $test->addTestFile($file); 
     73        } 
     74         
     75        /** 
     76         *  Tests for hidden files so as to skip them. Currently 
     77         *  only tests for Unix hidden files. 
     78         *  @param string $filename        Plain filename. 
     79         *  @return boolean                True if hidden file. 
     80         *  @access private 
     81         */ 
     82        function _isHidden($filename) { 
     83            return strncmp($filename, '.', 1) == 0; 
    6984        } 
    7085    } 
  • trunk/src/main/php/org/simpletest/errors.php

    r172 r740  
    11<?php 
    2     /** 
    3      *  base include file for SimpleTest 
    4      *  @package    SimpleTest 
    5      *  @subpackage UnitTester 
    6      *  @version    $Id: errors.php,v 1.20 2006/11/15 21:45:26 maugrim_t_r Exp $ 
    7      */ 
    8  
    9     /** @ignore - PHP5 compatibility fix. */ 
    10     if (! defined('E_STRICT')) { 
    11         define('E_STRICT', 2048); 
     2/** 
     3 *  base include file for SimpleTest 
     4 *  @package    SimpleTest 
     5 *  @subpackage UnitTester 
     6 *  @version    $Id: errors.php,v 1.28 2007/06/13 11:01:54 pachanga Exp $ 
     7 */ 
     8 
     9/** 
     10 * @ignore - PHP5 compatibility fix. 
     11 */ 
     12if (! defined('E_STRICT')) { 
     13    define('E_STRICT', 2048); 
     14
     15 
     16/**#@+ 
     17 * Includes SimpleTest files. 
     18 */ 
     19require_once dirname(__FILE__) . '/invoker.php'; 
     20require_once dirname(__FILE__) . '/test_case.php'; 
     21require_once dirname(__FILE__) . '/expectation.php'; 
     22/**#@-*/ 
     23 
     24/** 
     25 *    Extension that traps errors into an error queue. 
     26 *    @package SimpleTest 
     27 *    @subpackage UnitTester 
     28 */ 
     29class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { 
     30 
     31    /** 
     32     *    Stores the invoker to wrap. 
     33     *    @param SimpleInvoker $invoker  Test method runner. 
     34     */ 
     35    function SimpleErrorTrappingInvoker(&$invoker) { 
     36        $this->SimpleInvokerDecorator($invoker); 
     37    } 
     38 
     39    /** 
     40     *    Invokes a test method and dispatches any 
     41     *    untrapped errors. Called back from 
     42     *    the visiting runner. 
     43     *    @param string $method    Test method to call. 
     44     *    @access public 
     45     */ 
     46    function invoke($method) { 
     47        $context = &SimpleTest::getContext(); 
     48        $queue = &$context->get('SimpleErrorQueue'); 
     49        $queue->setTestCase($this->GetTestCase()); 
     50        set_error_handler('SimpleTestErrorHandler'); 
     51        parent::invoke($method); 
     52        while (list($severity, $message, $file, $line) = $queue->extract()) { 
     53            $severity = SimpleErrorQueue::getSeverityAsString($severity); 
     54            $test = &$this->getTestCase(); 
     55            $test->error($severity, $message, $file, $line); 
     56        } 
     57        restore_error_handler(); 
     58    } 
     59 
     60    function after($method) { 
     61        $context = &SimpleTest::getContext(); 
     62        $queue = &$context->get('SimpleErrorQueue'); 
     63        $queue->setTestCase($this->getTestCase()); 
     64        while (list($expected, $message) = $queue->extractExpectation()) { 
     65            $testCase = &$this->getTestCase(); 
     66 
     67            $testCase->fail( 
     68                sprintf('Expected PHP error [%s] not caught', $expected->_value) 
     69            ); 
     70        } 
     71        parent::after($method); 
     72    } 
     73
     74 
     75/** 
     76 *    Singleton error queue used to record trapped 
     77 *    errors. 
     78 *    @package  SimpleTest 
     79 *    @subpackage   UnitTester 
     80 */ 
     81class SimpleErrorQueue { 
     82    var $_queue; 
     83    var $_expectation_queue; 
     84    var $_test; 
     85 
     86    /** 
     87     *    Starts with an empty queue. 
     88     */ 
     89    function SimpleErrorQueue() { 
     90        $this->clear(); 
     91    } 
     92 
     93    /** 
     94     *    Sets the currently running test case. 
     95     *    @param SimpleTestCase $test    Test case to send messages to. 
     96     *    @access public 
     97     */ 
     98    function setTestCase(&$test) { 
     99        $this->_test = &$test; 
     100    } 
     101 
     102    /** 
     103     *    Adds an error to the front of the queue. 
     104     *    @param integer $severity       PHP error code. 
     105     *    @param string $content         Text of error. 
     106     *    @param string $filename        File error occoured in. 
     107     *    @param integer $line           Line number of error. 
     108     *    @access public 
     109     */ 
     110    function add($severity, $content, $filename, $line) { 
     111        $content = str_replace('%', '%%', $content); 
     112        if (count($this->_expectation_queue)) { 
     113            $this->_testLatestError($severity, $content, $filename, $line); 
     114        } else { 
     115            array_push( 
     116                    $this->_queue, 
     117                    array($severity, $content, $filename, $line)); 
     118        } 
     119    } 
     120 
     121    /** 
     122     *    Tests the error against the most recent expected 
     123     *    error. 
     124     *    @param integer $severity       PHP error code. 
     125     *    @param string $content         Text of error. 
     126     *    @param string $filename        File error occoured in. 
     127     *    @param integer $line           Line number of error. 
     128     *    @access private 
     129     */ 
     130    function _testLatestError($severity, $content, $filename, $line) { 
     131        list($expected, $message) = array_shift($this->_expectation_queue); 
     132        $severity = $this->getSeverityAsString($severity); 
     133        $is_match = $this->_test->assert( 
     134                $expected, 
     135                $content, 
     136                sprintf($message, "%s -> PHP error [$content] severity [$severity] in [$filename] line [$line]")); 
     137        if (! $is_match) { 
     138            $this->_test->error($severity, $content, $filename, $line); 
     139        } 
     140    } 
     141 
     142    /** 
     143     *    Pulls the earliest error from the queue. 
     144     *    @return     False if none, or a list of error 
     145     *                information. Elements are: severity 
     146     *                as the PHP error code, the error message, 
     147     *                the file with the error, the line number 
     148     *                and a list of PHP super global arrays. 
     149     *    @access public 
     150     */ 
     151    function extract() { 
     152        if (count($this->_queue)) { 
     153            return array_shift($this->_queue); 
     154        } 
     155        return false; 
     156    } 
     157 
     158    function extractExpectation() { 
     159        if (count($this->_expectation_queue)) { 
     160            return array_shift($this->_expectation_queue); 
     161        } 
     162        return false; 
     163    } 
     164 
     165    /** 
     166     *    Discards the contents of the error queue. 
     167     *    @access public 
     168     */ 
     169    function clear() { 
     170        $this->_queue = array(); 
     171        $this->_expectation_queue = array(); 
     172    } 
     173 
     174    /** 
     175     *    @deprecated 
     176     */ 
     177    function assertNoErrors($message) { 
     178        return $this->_test->assert( 
     179                new TrueExpectation(), 
     180                count($this->_queue) == 0, 
     181                sprintf($message, 'Should be no errors')); 
     182    } 
     183 
     184    /** 
     185     *    @deprecated 
     186     */ 
     187    function assertError($expected, $message) { 
     188        if (count($this->_queue) == 0) { 
     189            $this->_test->fail(sprintf($message, 'Expected error not found')); 
     190            return false; 
     191        } 
     192        list($severity, $content, $file, $line) = $this->extract(); 
     193        $severity = $this->getSeverityAsString($severity); 
     194        return $this->_test->assert( 
     195                $expected, 
     196                $content, 
     197                sprintf($message, "Expected PHP error [$content] severity [$severity] in [$file] line [$line]")); 
     198    } 
     199 
     200    /** 
     201     *    Sets up an expectation of an error. If this is 
     202     *    not fulfilled at the end of the test, a failure 
     203     *    will occour. If the error does happen, then this 
     204     *    will cancel it out and send a pass message. 
     205     *    @param SimpleExpectation $expected    Expected error match. 
     206     *    @param string $message                Message to display. 
     207     *    @access public 
     208     */ 
     209    function expectError($expected, $message) { 
     210        array_push($this->_expectation_queue, array($expected, $message)); 
     211    } 
     212 
     213    /** 
     214     *    Converts an error code into it's string 
     215     *    representation. 
     216     *    @param $severity  PHP integer error code. 
     217     *    @return           String version of error code. 
     218     *    @access public 
     219     *    @static 
     220     */ 
     221    function getSeverityAsString($severity) { 
     222        static $map = array( 
     223                E_STRICT => 'E_STRICT', 
     224                E_ERROR => 'E_ERROR', 
     225                E_WARNING => 'E_WARNING', 
     226                E_PARSE => 'E_PARSE', 
     227                E_NOTICE => 'E_NOTICE', 
     228                E_CORE_ERROR => 'E_CORE_ERROR', 
     229                E_CORE_WARNING => 'E_CORE_WARNING', 
     230                E_COMPILE_ERROR => 'E_COMPILE_ERROR', 
     231                E_COMPILE_WARNING => 'E_COMPILE_WARNING', 
     232                E_USER_ERROR => 'E_USER_ERROR', 
     233                E_USER_WARNING => 'E_USER_WARNING', 
     234                E_USER_NOTICE => 'E_USER_NOTICE'); 
     235    if(version_compare(phpversion(), '5.2.0', '>=')) { 
     236       $map[E_RECOVERABLE_ERROR] = 'E_RECOVERABLE_ERROR'; 
    12237    } 
    13  
    14     /**#@+ 
    15      * Includes SimpleTest files. 
    16      */ 
    17     require_once(dirname(__FILE__) . '/invoker.php'); 
    18     require_once(dirname(__FILE__) . '/test_case.php'); 
    19     require_once(dirname(__FILE__) . '/expectation.php'); 
    20  
    21     /** 
    22      *    Extension that traps errors into an error queue. 
    23      *    @package SimpleTest 
    24      *    @subpackage UnitTester 
    25      */ 
    26     class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { 
    27  
    28         /** 
    29          *    Stores the invoker to wrap. 
    30          *    @param SimpleInvoker $invoker  Test method runner. 
    31          */ 
    32         function SimpleErrorTrappingInvoker(&$invoker) { 
    33