Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
PHPUnit 3.6 can't catch generic Exceptions
  • Loading branch information
pento committed Oct 4, 2017
commit ba2dac8a6b31034b1d88ddc216d3297c0e5a9641
100 changes: 48 additions & 52 deletions tests/phpunit/tests/pomo/pluralForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down