From: Leszek Manicki Date: Wed, 30 Jan 2019 16:55:18 +0000 (+0100) Subject: Added future compat expectException to PHPUnit4And6Compat trait X-Git-Tag: 1.34.0-rc.0~2948^2 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=ec12e3cc7bb301386698c1cc7fa8128c279e2f8a;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 *