From ec12e3cc7bb301386698c1cc7fa8128c279e2f8a Mon Sep 17 00:00:00 2001 From: Leszek Manicki Date: Wed, 30 Jan 2019 17:55:18 +0100 Subject: [PATCH] Added future compat expectException to PHPUnit4And6Compat trait This allows PHPUnit 6 ready tests asserting the exception that is to be thrown (as setExpectedException is removed in PHPUnit 6). Bug: T208389 Change-Id: I13c58f37671092583a7fdfed7ccee9c2a4ecb136 --- tests/phpunit/PHPUnit4And6Compat.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/PHPUnit4And6Compat.php b/tests/phpunit/PHPUnit4And6Compat.php index 672ab4a4d6..79ce634fab 100644 --- a/tests/phpunit/PHPUnit4And6Compat.php +++ b/tests/phpunit/PHPUnit4And6Compat.php @@ -29,9 +29,9 @@ trait PHPUnit4And6Compat { * is a temporary backwards-compatibility layer while we transition. */ public function setExpectedException( $name, $message = '', $code = null ) { - if ( is_callable( [ $this, 'expectException' ] ) ) { + if ( is_callable( 'parent::expectException' ) ) { if ( $name !== null ) { - $this->expectException( $name ); + parent::expectException( $name ); } if ( $message !== '' ) { $this->expectExceptionMessage( $message ); @@ -44,6 +44,18 @@ trait PHPUnit4And6Compat { } } + /** + * Future-compatible layer for PHPUnit 4's setExpectedException. + */ + public function expectException( $exception ) { + if ( is_callable( 'parent::expectException' ) ) { + parent::expectException( $exception ); + return; + } + + parent::setExpectedException( $exception ); + } + /** * @see PHPUnit_Framework_TestCase::getMock * -- 2.20.1