From b3b95c3927f1225ce67c45f977e3e84d8baec298 Mon Sep 17 00:00:00 2001 From: David Causse Date: Tue, 17 Sep 2019 17:23:17 +0200 Subject: [PATCH] Add assertFileContains to MediaWikiTestCaseTrait Used by CirrusSearch unit tests. Change-Id: I1b67a9cddfca7fa06fb0b916981d1efde0764018 --- .../phpunit/MediaWikiIntegrationTestCase.php | 26 ------------------- tests/phpunit/MediaWikiTestCaseTrait.php | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index ecd5c05b17..6120467fd5 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -2393,32 +2393,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->mergeMwGlobalArrayValue( 'wgHooks', [ $hookName => [ $handler ] ] ); } - /** - * 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 ); - } - /** * Edits or creates a page/revision * @param string $pageName Page title diff --git a/tests/phpunit/MediaWikiTestCaseTrait.php b/tests/phpunit/MediaWikiTestCaseTrait.php index 4ccfe39491..918b51b7c9 100644 --- a/tests/phpunit/MediaWikiTestCaseTrait.php +++ b/tests/phpunit/MediaWikiTestCaseTrait.php @@ -29,4 +29,30 @@ trait MediaWikiTestCaseTrait { $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 ); + } } -- 2.20.1