Make WordPress Core

Changeset 44902


Ignore:
Timestamp:
03/15/2019 12:01:15 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve documentation for phpunit/includes/abstract-testcase.php.

Props andizer.
Fixes #46499.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r44823 r44902  
    4747    }
    4848
     49    /**
     50     * Retrieves the name of the class the static method is called in.
     51     *
     52     * @return string The class name.
     53     */
    4954    public static function get_called_class() {
    5055        if ( function_exists( 'get_called_class' ) ) {
     
    6267    }
    6368
     69    /**
     70     * Runs the routine before setting up all tests.
     71     */
    6472    public static function setUpBeforeClass() {
    6573        global $wpdb;
     
    8391    }
    8492
     93    /**
     94     * Runs the routine after all tests have been run.
     95     */
    8596    public static function tearDownAfterClass() {
    8697        parent::tearDownAfterClass();
     
    100111    }
    101112
     113    /**
     114     * Runs the routine before each test is executed.
     115     */
    102116    public function setUp() {
    103117        set_time_limit( 0 );
     
    166180    }
    167181
     182    /**
     183     * Cleans the global scope (e.g `$_GET` and `$_POST`).
     184     */
    168185    public function clean_up_global_scope() {
    169186        $_GET  = array();
     
    270287     * @global array $wp_current_filter
    271288     * @global array $wp_filter
    272      * @return void
    273289     */
    274290    protected function _backup_hooks() {
     
    290306     * @global array $wp_current_filter
    291307     * @global array $wp_filter
    292      * @return void
    293308     */
    294309    protected function _restore_hooks() {
     
    307322    }
    308323
     324    /**
     325     * Flushes the WordPress object cache.
     326     */
    309327    public static function flush_cache() {
    310328        global $wp_object_cache;
     
    342360    }
    343361
     362    /**
     363     * Starts a database transaction.
     364     */
    344365    public function start_transaction() {
    345366        global $wpdb;
     
    360381    }
    361382
     383    /**
     384     * Replaces the `CREATE TABLE` statement with a `CREATE TEMPORARY TABLE` statement.
     385     *
     386     * @param string $query The query to replace the statement for.
     387     * @return string The altered query.
     388     */
    362389    public function _create_temporary_tables( $query ) {
    363390        if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) {
     
    367394    }
    368395
     396    /**
     397     * Replaces the `DROP TABLE` statement with a `DROP TEMPORARY TABLE` statement.
     398     *
     399     * @param string $query The query to replace the statement for.
     400     * @return string The altered query.
     401     */
    369402    public function _drop_temporary_tables( $query ) {
    370403        if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) {
     
    374407    }
    375408
     409    /**
     410     * Retrieves the `wp_die()` handler.
     411     *
     412     * @param callable $handler The current die handler.
     413     * @return callable The test die handler.
     414     */
    376415    public function get_wp_die_handler( $handler ) {
    377416        return array( $this, 'wp_die_handler' );
    378417    }
    379418
     419    /**
     420     * Throws an exception when called.
     421     *
     422     * @throws WPDieException Exception containing the message.
     423     *
     424     * @param string $message The `wp_die()` message.
     425     */
    380426    public function wp_die_handler( $message ) {
    381427        if ( ! is_scalar( $message ) ) {
     
    386432    }
    387433
     434    /**
     435     * Sets up the expectations for testing a deprecated call.
     436     */
    388437    public function expectDeprecated() {
    389438        $annotations = $this->getAnnotations();
     
    406455    }
    407456
     457    /**
     458     * Handles a deprecated expectation.
     459     *
     460     * The DocBlock should contain `@expectedDeprecated` to trigger this.
     461     */
    408462    public function expectedDeprecated() {
    409463        $errors = array();
     
    494548    }
    495549
     550    /**
     551     * Adds a deprecated function to the list of caught deprecated calls.
     552     *
     553     * @param string $function The deprecated function.
     554     */
    496555    public function deprecated_function_run( $function ) {
    497556        if ( ! in_array( $function, $this->caught_deprecated ) ) {
     
    500559    }
    501560
     561    /**
     562     * Adds a function called in a wrong way to the list of `_doing_it_wrong()` calls.
     563     *
     564     * @param string $function The function to add.
     565     */
    502566    public function doing_it_wrong_run( $function ) {
    503567        if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) {
     
    506570    }
    507571
     572    /**
     573     * Asserts that the given value is an instance of WP_Error.
     574     *
     575     * @param mixed  $actual  The value to check.
     576     * @param string $message Optional. Message to display when the assertion fails.
     577     */
    508578    public function assertWPError( $actual, $message = '' ) {
    509579        $this->assertInstanceOf( 'WP_Error', $actual, $message );
    510580    }
    511581
     582    /**
     583     * Asserts that the given value is not an instance of WP_Error.
     584     *
     585     * @param mixed  $actual  The value to check.
     586     * @param string $message Optional. Message to display when the assertion fails.
     587     */
    512588    public function assertNotWPError( $actual, $message = '' ) {
    513589        if ( is_wp_error( $actual ) && '' === $message ) {
     
    517593    }
    518594
     595
     596    /**
     597     * Asserts that the given value is an instance of IXR_Error.
     598     *
     599     * @param mixed  $actual  The value to check.
     600     * @param string $message Optional. Message to display when the assertion fails.
     601     */
    519602    public function assertIXRError( $actual, $message = '' ) {
    520603        $this->assertInstanceOf( 'IXR_Error', $actual, $message );
    521604    }
    522605
     606    /**
     607     * Asserts that the given value is not an instance of IXR_Error.
     608     *
     609     * @param mixed  $actual  The value to check.
     610     * @param string $message Optional. Message to display when the assertion fails.
     611     */
    523612    public function assertNotIXRError( $actual, $message = '' ) {
    524613        if ( $actual instanceof IXR_Error && '' === $message ) {
     
    528617    }
    529618
     619    /**
     620     * Asserts that the given fields are present in the given object.
     621     *
     622     * @param object $object The object to check.
     623     * @param array  $fields The fields to check.
     624     */
    530625    public function assertEqualFields( $object, $fields ) {
    531626        foreach ( $fields as $field_name => $field_value ) {
     
    536631    }
    537632
     633    /**
     634     * Asserts that two values are equal, with whitespace differences discarded.
     635     *
     636     * @param string $expected The expected value.
     637     * @param string $actual   The actual value.
     638     */
    538639    public function assertDiscardWhitespace( $expected, $actual ) {
    539640        $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) );
     
    761862     * This method defines the constants after including files.
    762863     *
    763      * @param Text_Template $template
     864     * @param Text_Template $template The template to prepare.
    764865     */
    765866    public function prepareTemplate( Text_Template $template ) {
     
    9191020     *
    9201021     * @param string $dir Path to the directory to scan.
    921      *
    9221022     * @return array List of file paths.
    9231023     */
     
    9991099     *
    10001100     * @param string $microtime Time string generated by `microtime()`.
    1001      *
    10021101     * @return float `microtime()` output as a float.
    10031102     */
     
    10131112     *
    10141113     * @param int $user_id User ID.
    1015      *
    10161114     * @return bool True if the user was deleted.
    10171115     */
     
    10481146     * @param array $upload         Array of information about the uploaded file, provided by wp_upload_bits().
    10491147     * @param int   $parent_post_id Optional. Parent post ID.
    1050      *
    10511148     * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    10521149     */
     
    10851182     * @param int    $post_id Post ID.
    10861183     * @param string $date    Post date, in the format YYYY-MM-DD HH:MM:SS.
    1087      *
    10881184     * @return int|false 1 on success, or false on error.
    10891185     */
Note: See TracChangeset for help on using the changeset viewer.