4 * For code common to both MediaWikiUnitTestCase and MediaWikiIntegrationTestCase.
6 trait MediaWikiTestCaseTrait
{
8 * Returns a PHPUnit constraint that matches anything other than a fixed set of values. This can
9 * be used to whitelist values, e.g.
10 * $mock->expects( $this->never() )->method( $this->anythingBut( 'foo', 'bar' ) );
11 * which will throw if any unexpected method is called.
13 * @param mixed ...$values Values that are not matched
15 protected function anythingBut( ...$values ) {
16 return $this->logicalNot( $this->logicalOr(
17 ...array_map( [ $this, 'matches' ], $values )
22 * Return a PHPUnit mock that is expected to never have any methods called on it.
27 protected function createNoOpMock( $type ) {
28 $mock = $this->createMock( $type );
29 $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
34 * Check whether file contains given data.
35 * @param string $fileName
36 * @param string $actualData
37 * @param bool $createIfMissing If true, and file does not exist, create it with given data
42 protected function assertFileContains(
45 $createIfMissing = false,
48 if ( $createIfMissing ) {
49 if ( !file_exists( $fileName ) ) {
50 file_put_contents( $fileName, $actualData );
51 $this->markTestSkipped( "Data file $fileName does not exist" );
54 self
::assertFileExists( $fileName );
56 self
::assertEquals( file_get_contents( $fileName ), $actualData, $msg );