X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCaseTrait.php;h=918b51b7c9db1f671f7855c9e87915b2638ebbd9;hb=04cea76cbbd1c66ddfa2a674cf383ffb497234ae;hp=f047d826b5fcd54c38449571852f34d86758df3d;hpb=d8cc9ef907fbb76838f2726989aa642340c7eb38;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiTestCaseTrait.php b/tests/phpunit/MediaWikiTestCaseTrait.php index f047d826b5..918b51b7c9 100644 --- a/tests/phpunit/MediaWikiTestCaseTrait.php +++ b/tests/phpunit/MediaWikiTestCaseTrait.php @@ -26,7 +26,33 @@ trait MediaWikiTestCaseTrait { */ protected function createNoOpMock( $type ) { $mock = $this->createMock( $type ); - $mock->expects( $this->never() )->method( $this->anything() ); + $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) ); return $mock; } + + /** + * Check whether file contains given data. + * @param string $fileName + * @param string $actualData + * @param bool $createIfMissing If true, and file does not exist, create it with given data + * and skip the test. + * @param string $msg + * @since 1.30 + */ + protected function assertFileContains( + $fileName, + $actualData, + $createIfMissing = false, + $msg = '' + ) { + if ( $createIfMissing ) { + if ( !file_exists( $fileName ) ) { + file_put_contents( $fileName, $actualData ); + $this->markTestSkipped( "Data file $fileName does not exist" ); + } + } else { + self::assertFileExists( $fileName ); + } + self::assertEquals( file_get_contents( $fileName ), $actualData, $msg ); + } }