WordPress.org

Make WordPress Core

Changeset 1221 in tests


Ignore:
Timestamp:
02/28/2013 04:30:21 PM (5 years ago)
Author:
nacin
Message:

During test execution, all wp_die() calls should throw an exception.

If the wp_die() call is not expected, the test will result in an error. Expected wp_die() calls may be caught with $this->setExpectedException( $exception ), @expectedException, etc. For more, see http://www.phpunit.de/manual/3.8/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.exceptions.

Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/exceptions.php

    r903 r1221  
    66
    77/**
    8  * Exception for cases of wp_die()
     8 * General exception for wp_die()
     9 */
     10class WPDieException extends Exception {}
     11
     12/**
     13 * Exception for cases of wp_die(), for ajax tests.
    914 * This means there was an error (no output, and a call to wp_die)
    1015 *
     
    1318 * @since      3.4.0
    1419 */
    15 class WPAjaxDieStopException extends Exception {}
     20class WPAjaxDieStopException extends WPDieException {}
    1621
    1722/**
    18  * Exception for cases of wp_die()
     23 * Exception for cases of wp_die(), for ajax tests.
    1924 * This means execution of the ajax function should be halted, but the unit
    2025 * test can continue.  The function finished normally and there was not an
     
    2631 * @since      3.4.0
    2732 */
    28 class WPAjaxDieContinueException extends Exception {}
     33class WPAjaxDieContinueException extends WPDieException {}
  • trunk/includes/testcase.php

    r1127 r1221  
    1919        $this->clean_up_global_scope();
    2020        $this->start_transaction();
     21        add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
    2122    }
    2223
     
    2627        remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
    2728        remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
     29        remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
    2830    }
    2931
     
    6264            return 'DROP TEMPORARY TABLE ' . substr( $query, 10 );
    6365        return $query;
     66    }
     67
     68    function get_wp_die_handler( $handler ) {
     69        return array( $this, 'wp_die_handler' );
     70    }
     71
     72    function wp_die_handler( $message ) {
     73        throw new WPDieException( $message );
    6474    }
    6575
Note: See TracChangeset for help on using the changeset viewer.