mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
c36d2bd0e8
The codebase already used the …::class feature in many places. So this is more for consistency than anything. The …::class feature makes it much easier to do refactoring in the future. Note this patch is exclusively touching tests. That should make it relatively easy to review this. As long as the CI is fine with it, it should be ok. Right? ;-) Change-Id: I4d2adee76b4adbc83b2061161fd4e863ba833fcb
97 lines
2.3 KiB
PHP
97 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers EchoTargetPageMapper
|
|
*/
|
|
class EchoTargetPageMapperTest extends MediaWikiTestCase {
|
|
|
|
public function provideDataTestInsert() {
|
|
return [
|
|
[
|
|
'successful insert with next sequence = 1',
|
|
[ 'insert' => true, 'insertId' => 2 ],
|
|
1
|
|
],
|
|
[
|
|
'successful insert with insert id = 2',
|
|
[ 'insert' => true, 'insertId' => 2 ],
|
|
2
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideDataTestInsert
|
|
*/
|
|
public function testInsert( $message, $dbResult, $result ) {
|
|
$target = $this->mockEchoTargetPage();
|
|
$targetMapper = new EchoTargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) );
|
|
$this->assertEquals( $result, $targetMapper->insert( $target ), $message );
|
|
}
|
|
|
|
/**
|
|
* Mock object of EchoTargetPage
|
|
*/
|
|
protected function mockEchoTargetPage() {
|
|
$target = $this->getMockBuilder( EchoTargetPage::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$target->expects( $this->any() )
|
|
->method( 'toDbArray' )
|
|
->will( $this->returnValue( [] ) );
|
|
$target->expects( $this->any() )
|
|
->method( 'getPageId' )
|
|
->will( $this->returnValue( 2 ) );
|
|
$target->expects( $this->any() )
|
|
->method( 'getEventId' )
|
|
->will( $this->returnValue( 3 ) );
|
|
|
|
return $target;
|
|
}
|
|
|
|
/**
|
|
* Mock object of MWEchoDbFactory
|
|
*/
|
|
protected function mockMWEchoDbFactory( $dbResult ) {
|
|
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$dbFactory->expects( $this->any() )
|
|
->method( 'getEchoDb' )
|
|
->will( $this->returnValue( $this->mockDb( $dbResult ) ) );
|
|
|
|
return $dbFactory;
|
|
}
|
|
|
|
/**
|
|
* Returns a mock database object
|
|
* @return \Wikimedia\Rdbms\IDatabase
|
|
*/
|
|
protected function mockDb( array $dbResult ) {
|
|
$dbResult += [
|
|
'insert' => '',
|
|
'insertId' => '',
|
|
'select' => '',
|
|
'delete' => ''
|
|
];
|
|
$db = $this->getMockBuilder( DatabaseMysqli::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$db->expects( $this->any() )
|
|
->method( 'insert' )
|
|
->will( $this->returnValue( $dbResult['insert'] ) );
|
|
$db->expects( $this->any() )
|
|
->method( 'insertId' )
|
|
->will( $this->returnValue( $dbResult['insertId'] ) );
|
|
$db->expects( $this->any() )
|
|
->method( 'select' )
|
|
->will( $this->returnValue( $dbResult['select'] ) );
|
|
$db->expects( $this->any() )
|
|
->method( 'delete' )
|
|
->will( $this->returnValue( $dbResult['delete'] ) );
|
|
|
|
return $db;
|
|
}
|
|
|
|
}
|