From 1eba2e5e3ef3e7bea7d13e8629fc4ad8736c9251 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 4 Oct 2017 04:10:47 +0000 Subject: [PATCH] Tests: Some tests in [41722] were using newer PHPUnit features. `test_cache` used PHPUnit's object mocking to test some internal behaviour in `Plural_Forms`, but made use of the `willReturn()` method, which was introduced in PHPUnit 4.0 as shorthand for `will($this->returnValue())`. Fixed by switching to the longer form. Several tests used the `@expectedException` directive to catch generic `Exception` exceptions, which was added in PHPUnit 3.7. Fixed by changing to an explicit `try` / `catch` test. See #41562. git-svn-id: https://develop.svn.wordpress.org/trunk@41725 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/pomo/pluralForms.php | 102 +++++++++++------------ 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 98abcdce38..ab92ba3b1d 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -156,62 +156,58 @@ class PluralFormsTest extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - /** - * @expectedException Exception - * @expectedExceptionMessage Unknown symbol "#" - */ - public function test_invalid_operator() { - $pluralForms = new Plural_Forms( 'n # 2' ); + public function data_exceptions() { + return array( + array( + 'n # 2', // Invalid expression to parse + 'Unknown symbol "#"', // Expected exception message + false, // Whether to call the get() method or not + ), + array( + 'n & 1', + 'Unknown operator "&"', + false, + ), + array( + '((n)', + 'Mismatched parentheses', + false, + ), + array( + '(n))', + 'Mismatched parentheses', + false, + ), + array( + 'n : 2', + 'Missing starting "?" ternary operator', + false, + ), + array( + 'n ? 1', + 'Unknown operator "?"', + true, + ), + array( + 'n n', + 'Too many values remaining on the stack', + true, + ), + ); } /** - * @expectedException Exception - * @expectedExceptionMessage Unknown operator "&" + * @dataProvider data_exceptions */ - public function test_partial_operator() { - $pluralForms = new Plural_Forms( 'n & 1' ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Mismatched parentheses - */ - public function test_mismatched_open_paren() { - $pluralForms = new Plural_Forms( '((n)' ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Mismatched parentheses - */ - public function test_mismatched_close_paren() { - $pluralForms = new Plural_Forms( '(n))' ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Missing starting "?" ternary operator - */ - public function test_missing_ternary_operator() { - $pluralForms = new Plural_Forms( 'n : 2' ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Unknown operator "?" - */ - public function test_missing_ternary_else() { - $pluralForms = new Plural_Forms( 'n ? 1' ); - $pluralForms->get( 1 ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Too many values remaining on the stack - */ - public function test_overflow_stack() { - $pluralForms = new Plural_Forms( 'n n' ); - $pluralForms->get( 1 ); + public function test_exceptions( $expression, $expected_exception, $call_get ) { + try { + $pluralForms = new Plural_Forms( $expression ); + if( $call_get ) { + $pluralForms->get( 1 ); + } + } catch ( Exception $e ) { + $this->assertEquals( $expected_exception, $e->getMessage() ); + } } public function test_cache() { @@ -223,7 +219,7 @@ class PluralFormsTest extends WP_UnitTestCase { $mock->expects($this->once()) ->method('execute') ->with($this->identicalTo(2)) - ->willReturn(1); + ->will($this->returnValue(1)); $first = $mock->get( 2 ); $second = $mock->get( 2 );