From 2f491fba509bfe77c94e6520b996ae87190d4cf1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 18 Sep 2020 14:11:11 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@48999 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/pomo/pluralForms.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 3c84321652..0d5cc192a5 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -199,25 +199,17 @@ class PluralFormsTest extends WP_UnitTestCase { /** * Ensures that an exception is thrown when an invalid plural form is encountered. * - * The `@expectedException Exception` notation for PHPUnit cannot be used because expecting an - * exception of type `Exception` is not supported before PHPUnit 3.7. The CI tests for PHP 5.2 - * run on PHPUnit 3.6. - * * @ticket 41562 * @dataProvider data_exceptions */ - public function test_exceptions( $expression, $expected_exception, $call_get ) { - try { - $plural_forms = new Plural_Forms( $expression ); - if ( $call_get ) { - $plural_forms->get( 1 ); - } - } catch ( Exception $e ) { - $this->assertSame( $expected_exception, $e->getMessage() ); - return; - } + public function test_exceptions( $expression, $expected_message, $call_get ) { + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( $expected_message ); - $this->fail( 'Expected exception was not thrown.' ); + $plural_forms = new Plural_Forms( $expression ); + if ( $call_get ) { + $plural_forms->get( 1 ); + } } /**