wiki.techinc.nl/tests/phpunit/unit/linker/LinksMigrationTest.php
Thiemo Kreuz 61ae7504df Replace trivial usa of mock builder with createMock() shortcut
createMock() does the same, but is much easier to read.

A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.

Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
2022-07-15 16:43:48 +00:00

67 lines
1.9 KiB
PHP

<?php
use MediaWiki\Linker\LinksMigration;
use MediaWiki\Linker\LinkTargetLookup;
use MediaWiki\MainConfigNames;
/**
* @covers MediaWiki\Linker\LinksMigration
*/
class LinksMigrationTest extends MediaWikiUnitTestCase {
public function provideReadNew() {
yield [ SCHEMA_COMPAT_READ_NEW ];
yield [ SCHEMA_COMPAT_NEW ];
}
/**
* @dataProvider provideReadNew
* @covers \MediaWiki\Linker\LinksMigration::getLinksConditions
*/
public function testGetLinksConditionsReadNew( $configValue ) {
$title = new TitleValue( NS_USER, 'Someuser' );
$linkTargetStore = $this->createMock( LinkTargetLookup::class );
$linkTargetStore->method( 'getLinkTargetId' )
->with( $title )
->willReturn( 1 );
$linkTargetStore->expects( $this->never() )->method( 'acquireLinkTargetId' );
$config = new HashConfig(
[
MainConfigNames::TemplateLinksSchemaMigrationStage => $configValue
]
);
$linksMigration = new LinksMigration( $config, $linkTargetStore );
$this->assertSame(
[ 'tl_target_id' => 1 ],
$linksMigration->getLinksConditions( 'templatelinks', $title )
);
}
public function provideReadOld() {
yield [ SCHEMA_COMPAT_READ_OLD ];
}
/**
* @dataProvider provideReadOld
* @covers \MediaWiki\Linker\LinksMigration::getLinksConditions
*/
public function testGetLinksConditionsReadOld( $configValue ) {
$title = new TitleValue( NS_USER, 'Someuser' );
$linkTargetStore = $this->createMock( LinkTargetLookup::class );
$linkTargetStore->expects( $this->never() )->method( 'getLinkTargetId' );
$linkTargetStore->expects( $this->never() )->method( 'acquireLinkTargetId' );
$config = new HashConfig(
[
MainConfigNames::TemplateLinksSchemaMigrationStage => $configValue
]
);
$linksMigration = new LinksMigration( $config, $linkTargetStore );
$this->assertSame(
[ 'tl_namespace' => 2, 'tl_title' => 'Someuser' ],
$linksMigration->getLinksConditions( 'templatelinks', $title )
);
}
}