Make WordPress Core


Ignore:
Timestamp:
09/18/2020 02:11:11 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Simplify PluralFormsTest::test_exceptions().

Previously, the test had to use an older pattern for catching the generic Exception exceptions for compatibility with PHPUnit 3.6 on PHP 5.2.

Now that WordPress supports PHPUnit 5.4 as the minimum version, the expectException() method can be used directly.

Follow-up to [41725], [41730].

See #51344.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pomo/pluralForms.php

    r48937 r48999  
    200200     * Ensures that an exception is thrown when an invalid plural form is encountered.
    201201     *
    202      * The `@expectedException Exception` notation for PHPUnit cannot be used because expecting an
    203      * exception of type `Exception` is not supported before PHPUnit 3.7. The CI tests for PHP 5.2
    204      * run on PHPUnit 3.6.
    205      *
    206202     * @ticket 41562
    207203     * @dataProvider data_exceptions
    208204     */
    209     public function test_exceptions( $expression, $expected_exception, $call_get ) {
    210         try {
    211             $plural_forms = new Plural_Forms( $expression );
    212             if ( $call_get ) {
    213                 $plural_forms->get( 1 );
    214             }
    215         } catch ( Exception $e ) {
    216             $this->assertSame( $expected_exception, $e->getMessage() );
    217             return;
    218         }
    219 
    220         $this->fail( 'Expected exception was not thrown.' );
     205    public function test_exceptions( $expression, $expected_message, $call_get ) {
     206        $this->expectException( 'Exception' );
     207        $this->expectExceptionMessage( $expected_message );
     208
     209        $plural_forms = new Plural_Forms( $expression );
     210        if ( $call_get ) {
     211            $plural_forms->get( 1 );
     212        }
    221213    }
    222214
Note: See TracChangeset for help on using the changeset viewer.