From f640163bd14ebb03908d7f183a37bc291bead0c5 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 4 Oct 2017 13:52:13 +1100 Subject: [PATCH 1/2] Try the old PHPUnit syntax --- tests/phpunit/tests/pomo/pluralForms.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 98abcdce388ba..bebefd2cdea45 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -223,7 +223,7 @@ public function test_cache() { $mock->expects($this->once()) ->method('execute') ->with($this->identicalTo(2)) - ->willReturn(1); + ->will($this->returnValue(1)); $first = $mock->get( 2 ); $second = $mock->get( 2 ); From ba2dac8a6b31034b1d88ddc216d3297c0e5a9641 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 4 Oct 2017 14:47:32 +1100 Subject: [PATCH 2/2] PHPUnit 3.6 can't catch generic Exceptions --- tests/phpunit/tests/pomo/pluralForms.php | 100 +++++++++++------------ 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index bebefd2cdea45..ab92ba3b1dd3f 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -156,62 +156,58 @@ public function test_simple( $expression, $expected ) { $this->assertSame( $expected, $actual ); } - /** - * @expectedException Exception - * @expectedExceptionMessage Unknown symbol "#" - */ - public function test_invalid_operator() { - $pluralForms = new Plural_Forms( 'n # 2' ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Unknown operator "&" - */ - 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 ); + 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 Too many values remaining on the stack + * @dataProvider data_exceptions */ - 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() {