Merge "Remove Revision::getRevisionText from migrateArchiveText"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCaseTrait.php
index 77d7c04..918b51b 100644 (file)
@@ -17,4 +17,42 @@ trait MediaWikiTestCaseTrait {
                        ...array_map( [ $this, 'matches' ], $values )
                ) );
        }
+
+       /**
+        * Return a PHPUnit mock that is expected to never have any methods called on it.
+        *
+        * @param string $type
+        * @return object
+        */
+       protected function createNoOpMock( $type ) {
+               $mock = $this->createMock( $type );
+               $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 );
+       }
 }