Make WordPress Core

Changeset 48996


Ignore:
Timestamp:
09/18/2020 01:22:22 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Consistently use the expectException() method instead of the older @expectedException annotation.

See https://thephp.cc/news/2016/02/questioning-phpunit-best-practices

The method is available since PHPUnit 5.2, and WordPress currently supports PHPUnit 5.4 as the minimum version.

Follow-up to [48993].

See #51344.

Location:
trunk/tests/phpunit/tests
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/DeletePlugin.php

    r48939 r48996  
    1111 */
    1212class Tests_Ajax_Delete_Plugin extends WP_Ajax_UnitTestCase {
    13         /**
    14          * @expectedException WPAjaxDieStopException
    15          * @expectedExceptionMessage -1
    16          */
     13
    1714        public function test_missing_nonce() {
     15                $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    1816                $this->_handleAjax( 'delete-plugin' );
    1917        }
  • trunk/tests/phpunit/tests/ajax/UpdatePlugin.php

    r48939 r48996  
    1111 */
    1212class Tests_Ajax_Update_Plugin extends WP_Ajax_UnitTestCase {
    13         /**
    14          * @expectedException WPAjaxDieStopException
    15          * @expectedExceptionMessage -1
    16          */
     13
    1714        public function test_missing_nonce() {
     15                $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    1816                $this->_handleAjax( 'update-plugin' );
    1917        }
  • trunk/tests/phpunit/tests/comment/wpAllowComment.php

    r48121 r48996  
    5353        }
    5454
    55         /**
    56          * @expectedException WPDieException
    57          */
    5855        public function test_die_as_duplicate_if_comment_author_name_and_emails_match() {
     56                $this->expectException( 'WPDieException' );
     57
    5958                $now          = time();
    6059                $comment_data = array(
  • trunk/tests/phpunit/tests/compat.php

    r48937 r48996  
    180180        }
    181181
    182         /**
    183          * @expectedException PHPUnit_Framework_Error_Deprecated
    184          */
    185182        function test_json_encode_decode() {
     183                $this->expectException( 'PHPUnit_Framework_Error_Deprecated' );
     184
    186185                require_once ABSPATH . WPINC . '/class-json.php';
    187186                $json = new Services_JSON();
  • trunk/tests/phpunit/tests/db.php

    r48979 r48996  
    525525        }
    526526
    527         /**
    528          * @expectedException WPDieException
    529          */
    530527        function test_bail() {
    531528                global $wpdb;
     529
     530                $this->expectException( 'WPDieException' );
    532531                $wpdb->bail( 'Database is dead.' );
    533532        }
  • trunk/tests/phpunit/tests/formatting/redirect.php

    r48937 r48996  
    2525         *
    2626         * @dataProvider get_bad_status_codes
    27          * @expectedException WPDieException
    2827         *
    2928         * @param string $location The path or URL to redirect to.
     
    3130         */
    3231        public function test_wp_redirect_bad_status_code( $location, $status ) {
     32                $this->expectException( 'WPDieException' );
     33
    3334                wp_redirect( $location, $status );
    3435        }
  • trunk/tests/phpunit/tests/includes/helpers.php

    r48939 r48996  
    269269        /**
    270270         * @ticket 36166
    271          * @expectedException WPDieException
    272271         */
    273272        public function test_die_handler_should_handle_wp_error() {
     273                $this->expectException( 'WPDieException' );
     274
    274275                wp_die( new WP_Error( 'test', 'test' ) );
    275276        }
     
    277278        /**
    278279         * @ticket 46813
    279          * @expectedException WPDieException
    280280         */
    281281        public function test_die_handler_should_not_cause_doing_it_wrong_notice_without_wp_query_set() {
     282                $this->expectException( 'WPDieException' );
    282283                unset( $GLOBALS['wp_query'] );
    283284
  • trunk/tests/phpunit/tests/option/option.php

    r48937 r48996  
    102102        /**
    103103         * @ticket 23289
    104          * @expectedException WPDieException
    105104         */
    106105        function test_special_option_name_alloption() {
     106                $this->expectException( 'WPDieException' );
    107107                delete_option( 'alloptions' );
    108108        }
     
    110110        /**
    111111         * @ticket 23289
    112          * @expectedException WPDieException
    113112         */
    114113        function test_special_option_name_notoptions() {
     114                $this->expectException( 'WPDieException' );
    115115                delete_option( 'notoptions' );
    116116        }
  • trunk/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php

    r48236 r48996  
    164164                $request_id = wp_create_user_request( 'removal-requester@example.com', 'remove_personal_data' );
    165165
    166                 $this->setExpectedException( 'WPDieException' );
     166                $this->expectException( 'WPDieException' );
    167167                $this->expectOutputString( '{"success":false,"data":"Invalid request ID when generating export file."}' );
    168168                wp_privacy_generate_personal_data_export_file( $request_id );
     
    175175         */
    176176        public function test_invalid_request_id() {
    177                 $this->setExpectedException( 'WPDieException' );
     177                $this->expectException( 'WPDieException' );
    178178                $this->expectOutputString( '{"success":false,"data":"Invalid request ID when generating export file."}' );
    179179                wp_privacy_generate_personal_data_export_file( 123456789 );
     
    195195                );
    196196
    197                 $this->setExpectedException( 'WPDieException' );
     197                $this->expectException( 'WPDieException' );
    198198                $this->expectOutputString( '{"success":false,"data":"Invalid email address when generating export file."}' );
    199199                wp_privacy_generate_personal_data_export_file( $request_id );
     
    209209                touch( untrailingslashit( self::$exports_dir ) );
    210210
    211                 $this->setExpectedException( 'WPDieException' );
     211                $this->expectException( 'WPDieException' );
    212212                $this->expectOutputString( '{"success":false,"data":"Unable to create export folder."}' );
    213213                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
  • trunk/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php

    r48330 r48996  
    257257         */
    258258        private function _setup_expected_failure( $expected_output ) {
    259                 $this->setExpectedException( 'WPDieException' );
     259                $this->expectException( 'WPDieException' );
    260260                $this->expectOutputString( $expected_output );
    261261        }
Note: See TracChangeset for help on using the changeset viewer.