Make WordPress Core

Ticket #46499: 46499-2.diff

File 46499-2.diff, 7.2 KB (added by andizer, 5 years ago)

Removed the @return void

  • tests/phpunit/includes/abstract-testcase.php

     
    4646                return $factory;
    4747        }
    4848
     49        /**
     50         * Retrieves the name of the current called class.
     51         *
     52         * @return string The class name.
     53         */
    4954        public static function get_called_class() {
    5055                if ( function_exists( 'get_called_class' ) ) {
    5156                        return get_called_class();
     
    6166                return $backtrace[2]['class'];
    6267        }
    6368
     69        /**
     70         * Runs the routine before setting up all tests.
     71         */
    6472        public static function setUpBeforeClass() {
    6573                global $wpdb;
    6674
     
    8290                self::commit_transaction();
    8391        }
    8492
     93        /**
     94         * Runs the routine after all tests have been ran.
     95         */
    8596        public static function tearDownAfterClass() {
    8697                parent::tearDownAfterClass();
    8798
     
    99110                self::commit_transaction();
    100111        }
    101112
     113        /**
     114         * Runs the routine before each test is executed.
     115         */
    102116        public function setUp() {
    103117                set_time_limit( 0 );
    104118
     
    165179                wp_set_current_user( 0 );
    166180        }
    167181
     182        /**
     183         * Cleans the global scope (e.g the $_GET and $_POST).
     184         */
    168185        public function clean_up_global_scope() {
    169186                $_GET  = array();
    170187                $_POST = array();
     
    306323                }
    307324        }
    308325
     326        /**
     327         * Flushes the WordPress cache.
     328         */
    309329        public static function flush_cache() {
    310330                global $wp_object_cache;
    311331                $wp_object_cache->group_ops      = array();
     
    341361                }
    342362        }
    343363
     364        /**
     365         * Starts a database transaction.
     366         */
    344367        public function start_transaction() {
    345368                global $wpdb;
    346369                $wpdb->query( 'SET autocommit = 0;' );
     
    359382                $wpdb->query( 'COMMIT;' );
    360383        }
    361384
     385        /**
     386         * Replaces the create table statement for a create temporary table statement.
     387         *
     388         * @param string $query The query to replace the statement for.
     389         *
     390         * @return string The altered query.
     391         */
    362392        public function _create_temporary_tables( $query ) {
    363393                if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) {
    364394                        return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 );
     
    366396                return $query;
    367397        }
    368398
     399        /**
     400         * Replaces the drop table statement for a drop temporary table statement.
     401         *
     402         * @param string $query The query to replace the statement for.
     403         *
     404         * @return string The altered query.
     405         */
    369406        public function _drop_temporary_tables( $query ) {
    370407                if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) {
    371408                        return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 );
     
    373410                return $query;
    374411        }
    375412
     413        /**
     414         * Retrieves the die handler.
     415         *
     416         * @param callable $handler The current die handler.
     417         *
     418         * @return callable The test die handler.
     419         */
    376420        public function get_wp_die_handler( $handler ) {
    377421                return array( $this, 'wp_die_handler' );
    378422        }
    379423
     424        /**
     425         * Throws an exception when called.
     426         *
     427         * @param string $message The die message.
     428         *
     429         * @throws WPDieException Exception containing the message.
     430         */
    380431        public function wp_die_handler( $message ) {
    381432                if ( ! is_scalar( $message ) ) {
    382433                        $message = '0';
     
    385436                throw new WPDieException( $message );
    386437        }
    387438
     439        /**
     440         * Sets up the expectations for testing a deprecated call.
     441         */
    388442        public function expectDeprecated() {
    389443                $annotations = $this->getAnnotations();
    390444                foreach ( array( 'class', 'method' ) as $depth ) {
     
    405459                add_action( 'doing_it_wrong_trigger_error', '__return_false' );
    406460        }
    407461
     462        /**
     463         * Handles a deprecated expectation. The docbloc should contain `@expectedDeprecated`
     464         * to trigger this.
     465         */
    408466        public function expectedDeprecated() {
    409467                $errors = array();
    410468
     
    493551                }
    494552        }
    495553
     554        /**
     555         * Adds a deprecated function to the list of caught deprecated calles.
     556         *
     557         * @param string $function The deprecated function.
     558         */
    496559        public function deprecated_function_run( $function ) {
    497560                if ( ! in_array( $function, $this->caught_deprecated ) ) {
    498561                        $this->caught_deprecated[] = $function;
     
    499562                }
    500563        }
    501564
     565        /**
     566         * Adds a function that has been called in a wrong way to the list of
     567         * doing it wrong calls.
     568         *
     569         * @param string $function The function to add.
     570         */
    502571        public function doing_it_wrong_run( $function ) {
    503572                if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) {
    504573                        $this->caught_doing_it_wrong[] = $function;
     
    505574                }
    506575        }
    507576
     577        /**
     578         * Checks if the given actual value is an instance of WP_Error.
     579         *
     580         * @param mixed  $actual  The actual value to check.
     581         * @param string $message The message to show when test fails.
     582         */
    508583        public function assertWPError( $actual, $message = '' ) {
    509584                $this->assertInstanceOf( 'WP_Error', $actual, $message );
    510585        }
    511586
     587        /**
     588         * Checks if the given value isn't an instance of WP_Error.
     589         *
     590         * @param mixed  $actual  The actual value to check.
     591         * @param string $message The message to show when test fails.
     592         */
    512593        public function assertNotWPError( $actual, $message = '' ) {
    513594                if ( is_wp_error( $actual ) && '' === $message ) {
    514595                        $message = $actual->get_error_message();
     
    516597                $this->assertNotInstanceOf( 'WP_Error', $actual, $message );
    517598        }
    518599
     600
     601        /**
     602         * Checks if the given actual value is an instance of IXR_Error.
     603         *
     604         * @param mixed  $actual  The actual value to check.
     605         * @param string $message The message to show when test fails.
     606         */
    519607        public function assertIXRError( $actual, $message = '' ) {
    520608                $this->assertInstanceOf( 'IXR_Error', $actual, $message );
    521609        }
    522610
     611        /**
     612         * Checks if the given value isn't an instance of IXR_Error.
     613         *
     614         * @param mixed  $actual  The actual value to check.
     615         * @param string $message The message to show when test fails.
     616         */
    523617        public function assertNotIXRError( $actual, $message = '' ) {
    524618                if ( $actual instanceof IXR_Error && '' === $message ) {
    525619                        $message = $actual->message;
     
    527621                $this->assertNotInstanceOf( 'IXR_Error', $actual, $message );
    528622        }
    529623
     624        /**
     625         * Checks if the given fields are present in the given object.
     626         *
     627         * @param object $object The actual object.
     628         * @param array  $fields The fields to check.
     629         */
    530630        public function assertEqualFields( $object, $fields ) {
    531631                foreach ( $fields as $field_name => $field_value ) {
    532632                        if ( $object->$field_name != $field_value ) {
     
    535635                }
    536636        }
    537637
     638        /**
     639         * Performs an assertion with whitespace being discarded from the expected and actual values.
     640         *
     641         * @param string $expected The expected value.
     642         * @param string $actual   The actual value.
     643         */
    538644        public function assertDiscardWhitespace( $expected, $actual ) {
    539645                $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) );
    540646        }
     
    701807         *
    702808         * @since 3.5.0
    703809         *
    704          * @param int $ticket_id Ticket number.
     810         * @param int $ticket_id Ticket number
    705811         */
    706812        public function knownWPBug( $ticket_id ) {
    707813                if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) {
     
    760866         *
    761867         * This method defines the constants after including files.
    762868         *
    763          * @param Text_Template $template
     869         * @param Text_Template $template The template to prepare.
    764870         */
    765871        public function prepareTemplate( Text_Template $template ) {
    766872                $template->setVar( array( 'constants' => '' ) );