The default will remain PHPUnit 4.x due to PHP 5.5 support. But, we should allow developers to run tests with newer PHPUnit versions which are noticably faster (especially for code coverage reports). * <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0> PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock(). It instead introduces the shortcut createMock() which has better defaults than getMockBuilder(). For example, it sets 'disableArgumentCloning' and other things by default. Going forward, code should either use getMockBuilder directly and configure it using the setter methods (instead of the confusing variadic arguments of getMock) or simply use the new minimalistic createMock method. This patch backports the createMock method to MediaWikiTestCase so that we can start using it. Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
*/
|
|
class FileContentHandlerTest extends MediaWikiLangTestCase {
|
|
/**
|
|
* @var FileContentHandler
|
|
*/
|
|
private $handler;
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->handler = new FileContentHandler();
|
|
}
|
|
|
|
public function testIndexMapping() {
|
|
$mockEngine = $this->createMock( 'SearchEngine' );
|
|
|
|
$mockEngine->expects( $this->atLeastOnce() )
|
|
->method( 'makeSearchFieldMapping' )
|
|
->willReturnCallback( function ( $name, $type ) {
|
|
$mockField =
|
|
$this->getMockBuilder( 'SearchIndexFieldDefinition' )
|
|
->setMethods( [ 'getMapping' ] )
|
|
->setConstructorArgs( [ $name, $type ] )
|
|
->getMock();
|
|
return $mockField;
|
|
} );
|
|
|
|
$map = $this->handler->getFieldsForSearchIndex( $mockEngine );
|
|
$expect = [
|
|
'file_media_type' => 1,
|
|
'file_mime' => 1,
|
|
'file_size' => 1,
|
|
'file_width' => 1,
|
|
'file_height' => 1,
|
|
'file_bits' => 1,
|
|
'file_resolution' => 1,
|
|
'file_text' => 1,
|
|
];
|
|
foreach ( $map as $name => $field ) {
|
|
$this->assertInstanceOf( 'SearchIndexField', $field );
|
|
$this->assertEquals( $name, $field->getName() );
|
|
unset( $expect[$name] );
|
|
}
|
|
$this->assertEmpty( $expect );
|
|
}
|
|
}
|