Make WordPress Core

Changeset 31306


Ignore:
Timestamp:
01/30/2015 04:47:44 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce setExpectedDeprecated() and setExpectedIncorrectUsage() methods to `WP_UnitTestCase.

These methods provide a procedural alternative to the @expectedDeprecated
and @expectedIncorrectUsage test annotations, and parallel PHPUnit's native
setExpectedException().

Props prasoon2211, jdgrimes.
Fixes #28486.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

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

    r31046 r31306  
    244244            $this->fail( "Unexpected incorrect usage notice for $unexpected" );
    245245        }
     246    }
     247
     248    /**
     249     * Declare an expected `_deprecated_function()` or `_deprecated_argument()` call from within a test.
     250     *
     251     * @since 4.2.0
     252     *
     253     * @param string $deprecated Name of the function, method, class, or argument that is deprecated. Must match
     254     *                           first parameter of the `_deprecated_function()` or `_deprecated_argument()` call.
     255     */
     256    public function setExpectedDeprecated( $deprecated ) {
     257        array_push( $this->expected_deprecated, $deprecated );
     258    }
     259
     260    /**
     261     * Declare an expected `_doing_it_wrong()` call from within a test.
     262     *
     263     * @since 4.2.0
     264     *
     265     * @param string $deprecated Name of the function, method, or class that appears in the first argument of the
     266     *                           source `_doing_it_wrong()` call.
     267     */
     268    public function setExpectedIncorrectUsage( $doing_it_wrong ) {
     269        array_push( $this->expected_doing_it_wrong, $doing_it_wrong );
    246270    }
    247271
  • trunk/tests/phpunit/tests/includes/helpers.php

    r31046 r31306  
    169169        $this->assertFalse( isset( $stati['foo'] ) );
    170170    }
     171
     172    /**
     173     * @ticket 28486
     174     */
     175    public function test_setExpectedDeprecated() {
     176        $this->setExpectedDeprecated( 'Tests_TestHelpers::mock_deprecated' );
     177        $this->mock_deprecated();
     178    }
     179
     180    /**
     181     * @ticket 28486
     182     */
     183    public function test_setExpectedIncorrectUsage() {
     184        $this->setExpectedIncorrectUsage( 'Tests_TestHelpers::mock_incorrect_usage' );
     185        $this->mock_incorrect_usage();
     186    }
     187
     188    protected function mock_deprecated() {
     189        _deprecated_function( __METHOD__, '2.5' );
     190    }
     191
     192    protected function mock_incorrect_usage() {
     193        _doing_it_wrong( __METHOD__, __( 'Incorrect usage test' ), '2.5' );
     194    }
    171195}
Note: See TracChangeset for help on using the changeset viewer.