Added future compat expectException to PHPUnit4And6Compat trait
authorLeszek Manicki <leszek.manicki@wikimedia.de>
Wed, 30 Jan 2019 16:55:18 +0000 (17:55 +0100)
committerTarrow <thomas.arrow_ext@wikimedia.de>
Mon, 4 Feb 2019 15:07:45 +0000 (15:07 +0000)
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

index 672ab4a..79ce634 100644 (file)
@@ -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
         *