Make WordPress Core

Changeset 39 in tests


Ignore:
Timestamp:
09/27/2007 03:50:17 PM (17 years ago)
Author:
nbachiyski
Message:

Catch all errors, which PHPUnit does and fail the test if one occured

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • wp-test.php

    r38 r39  
    4747
    4848// initialize wp
    49 echo "Testing branch ".DIR_WP."\n";
    5049define('WP_INSTALLING', 1);
    5150require_once(ABSPATH.'wp-settings.php');
  • wp-testcase/test_cron.php

    r31 r39  
    1111
    1212    function tearDown() {
     13        parent::tearDown();
    1314        // make sure the schedule is clear
    1415        _set_cron_array(array());
  • wp-testcase/test_includes_cache.php

    r23 r39  
    55
    66    function setUp() {
     7        parent::setUp();
    78        // create two cache objects with a shared cache dir
    89        // this simulates a typical cache situation, two separate requests interacting
     
    1213
    1314    function tearDown() {
     15        parent::tearDown();
    1416        wp_cache_flush();
    1517    }
  • wp-testcase/test_meta.php

    r22 r39  
    66
    77    function setUp() {
     8        parent::setUp();
    89        $this->val = true;
    910    }
    1011
    1112    function tearDown() {
     13        parent::tearDown();
    1214        $this->val = false;
    1315    }
  • wp-testcase/test_user_capabilities.php

    r16 r39  
    77
    88    function setUp() {
     9        parent::setUp();
    910        // keep track of users we create
    1011        $user_ids = array();
     
    1213
    1314    function tearDown() {
     15        parent::tearDown();
    1416        // delete any users that were created during tests
    1517        foreach ($this->user_ids as $id)
  • wp-testdata/sample_blogs.php

    r27 r39  
    1212
    1313    function setUp() {
     14        parent::setUp();
    1415        $this->author = get_userdatabylogin(WP_USER_NAME);
    1516        $this->_delete_all_posts();
  • wp-testlib/base.php

    r32 r39  
    55#require_once('PHPUnit.php');
    66require_once('PHPUnit/Framework.php');
     7require_once('PHPUnit/Util/ErrorHandler.php');
    78
    89// test cases should extend WPTestCase instead of PHPUnit_TestCase for three reasons:
     
    1314
    1415class WPTestCase extends PHPUnit_Framework_TestCase {
     16
     17    function setUp() {
     18        // error types taken from PHPUnit_Framework_TestResult::run
     19        $this->_phpunit_err_mask = E_USER_ERROR | E_NOTICE | E_STRICT;
     20        if (version_compare(phpversion(), '5.2.0RC1', '>=')) {
     21            $this->_phpunit_err_mask |= E_RECOVERABLE_ERROR;
     22        }
     23        $this->_old_handler = set_error_handler(array(&$this, '_error_handler'));
     24        if (is_null($this->_old_handler)) {
     25            restore_error_handler();
     26        }
     27    }
     28
     29    function tearDown() {
     30        if (!is_null($this->_old_handler)) {
     31            restore_error_handler();
     32        }
     33    }
     34
     35    /**
     36     * Treat any error, which wasn't handled by PHPUnit as a failure
     37     */
     38    function _error_handler($errno, $errstr, $errfile, $errline) {
     39        if ($errno | $this->_phpunit_err_mask) {
     40            PHPUnit_Util_ErrorHandler($errno, $errstr, $errfile, $errline);
     41        } else {
     42            error_log("Testing: $errstr in $errfile on line $errline");
     43            //TODO: we should raise custom exception here, sth like WP_PHPError
     44            throw new PHPUnit_Framework_Error(
     45                $errstr,
     46                $errno,
     47                $errfile,
     48                $errline,
     49                $trace
     50            );
     51        }
     52    }
    1553
    1654    function _query_filter($q) {
Note: See TracChangeset for help on using the changeset viewer.