mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
Merge "Use PHPUnit's shortcuts where it makes sense"
This commit is contained in:
commit
630e415ebb
|
@ -13,7 +13,7 @@ class ApiEchoPushSubscriptionsCreateTest extends ApiTestCase {
|
|||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function setUp(): void {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->setMwGlobals( [
|
||||
'wgEchoEnablePush' => true,
|
||||
|
|
|
@ -19,7 +19,7 @@ class ApiEchoPushSubscriptionsDeleteTest extends ApiTestCase {
|
|||
/** @var User */
|
||||
private $otherUser;
|
||||
|
||||
public function setUp(): void {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->setMwGlobals( [
|
||||
'wgEchoEnablePush' => true,
|
||||
|
|
|
@ -29,12 +29,10 @@ class ContainmentSetTest extends MediaWikiIntegrationTestCase {
|
|||
$inner = [ 'bing', 'bang' ];
|
||||
// We use a mock instead of the real thing for the $this->once() assertion
|
||||
// verifying that the cache doesn't just keep asking the inner object
|
||||
$list = $this->getMockBuilder( EchoArrayList::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$list = $this->createMock( EchoArrayList::class );
|
||||
$list->expects( $this->once() )
|
||||
->method( 'getValues' )
|
||||
->will( $this->returnValue( $inner ) );
|
||||
->willReturn( $inner );
|
||||
$list->method( 'getCacheKey' )->willReturn( '' );
|
||||
|
||||
$cached = new EchoCachedList( $wanCache, 'test_key', $list );
|
||||
|
|
|
@ -54,7 +54,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ),
|
||||
$this->mockEchoNotificationMapper(),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -67,7 +67,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ),
|
||||
$this->mockEchoNotificationMapper(),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -83,7 +83,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ),
|
||||
$this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -96,7 +96,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ),
|
||||
$this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -109,7 +109,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ),
|
||||
$this->mockEchoNotificationMapper(),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -122,7 +122,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ),
|
||||
$this->mockEchoNotificationMapper(),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
@ -134,57 +134,35 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$dbResult += [
|
||||
'markRead' => true
|
||||
];
|
||||
$gateway = $this->getMockBuilder( EchoUserNotificationGateway::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$gateway->expects( $this->any() )
|
||||
->method( 'markRead' )
|
||||
->will( $this->returnValue( $dbResult['markRead'] ) );
|
||||
$gateway->expects( $this->any() )
|
||||
->method( 'getDB' )
|
||||
->will( $this->returnValue(
|
||||
$this->getMockBuilder( IDatabase::class )
|
||||
->disableOriginalConstructor()->getMock()
|
||||
) );
|
||||
$gateway = $this->createMock( EchoUserNotificationGateway::class );
|
||||
$gateway->method( 'markRead' )
|
||||
->willReturn( $dbResult['markRead'] );
|
||||
$gateway->method( 'getDB' )
|
||||
->willReturn( $this->createMock( IDatabase::class ) );
|
||||
|
||||
return $gateway;
|
||||
}
|
||||
|
||||
public function mockEchoNotificationMapper( array $result = [] ) {
|
||||
$mapper = $this->getMockBuilder( EchoNotificationMapper::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$mapper->expects( $this->any() )
|
||||
->method( 'fetchUnreadByUser' )
|
||||
->will( $this->returnValue( $result ) );
|
||||
$mapper = $this->createMock( EchoNotificationMapper::class );
|
||||
$mapper->method( 'fetchUnreadByUser' )
|
||||
->willReturn( $result );
|
||||
|
||||
return $mapper;
|
||||
}
|
||||
|
||||
public function mockEchoTargetPageMapper() {
|
||||
return $this->getMockBuilder( EchoTargetPageMapper::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
protected function mockEchoNotification() {
|
||||
$notification = $this->getMockBuilder( EchoNotification::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$notification->expects( $this->any() )
|
||||
->method( 'getEvent' )
|
||||
->will( $this->returnValue( $this->mockEchoEvent() ) );
|
||||
$notification = $this->createMock( EchoNotification::class );
|
||||
$notification->method( 'getEvent' )
|
||||
->willReturn( $this->mockEchoEvent() );
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
protected function mockEchoEvent() {
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getId' )
|
||||
->will( $this->returnValue( 1 ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getId' )
|
||||
->willReturn( 1 );
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
@ -195,7 +173,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
$this->cache,
|
||||
$this->mockEchoUserNotificationGateway(),
|
||||
$this->mockEchoNotificationMapper(),
|
||||
$this->mockEchoTargetPageMapper(),
|
||||
$this->createMock( EchoTargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
$this->getServiceContainer()->getReadOnlyMode()
|
||||
|
|
|
@ -58,9 +58,7 @@ class UnreadWikisTest extends MediaWikiIntegrationTestCase {
|
|||
* @return MWEchoDbFactory
|
||||
*/
|
||||
protected function mockMWEchoDbFactory( $db ) {
|
||||
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbFactory = $this->createMock( MWEchoDbFactory::class );
|
||||
$dbFactory->expects( $this->any() )
|
||||
->method( 'getSharedDb' )
|
||||
->will( $this->returnValue( $db ) );
|
||||
|
|
|
@ -22,12 +22,9 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
wfGetDB( DB_PRIMARY )->insert( 'watchlist', $rows, __METHOD__ );
|
||||
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getTitle' )
|
||||
->will( $this->returnValue( $title ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
|
||||
$it = EchoUserLocator::locateUsersWatchingTitle( $event, 10 );
|
||||
$this->assertCount( 50, $it );
|
||||
|
@ -76,10 +73,9 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
if ( $expect instanceof Closure ) {
|
||||
list( $expect, $title ) = $expect();
|
||||
}
|
||||
$event = $this->mockEchoEvent();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getTitle' )
|
||||
->will( $this->returnValue( $title ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
|
||||
$users = EchoUserLocator::locateTalkPageOwner( $event );
|
||||
$this->assertEquals( $expect, array_keys( $users ), $message );
|
||||
|
@ -114,13 +110,11 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
/* $summary = */ 'summary'
|
||||
);
|
||||
|
||||
$event = $this->mockEchoEvent();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getTitle' )
|
||||
->will( $this->returnValue( $title ) );
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getAgent' )
|
||||
->will( $this->returnValue( User::newFromId( 123 ) ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
$event->method( 'getAgent' )
|
||||
->willReturn( User::newFromId( 123 ) );
|
||||
|
||||
$users = EchoUserLocator::locateArticleCreator( $event );
|
||||
$this->assertEquals( $expect, array_keys( $users ), $message );
|
||||
|
@ -158,10 +152,9 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider locateEventAgentProvider
|
||||
*/
|
||||
public function testLocateEventAgent( $message, $expect, User $agent = null ) {
|
||||
$event = $this->mockEchoEvent();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getAgent' )
|
||||
->will( $this->returnValue( $agent ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getAgent' )
|
||||
->willReturn( $agent );
|
||||
|
||||
$users = EchoUserLocator::locateEventAgent( $event );
|
||||
$this->assertEquals( $expect, array_keys( $users ), $message );
|
||||
|
@ -236,12 +229,10 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider locateFromEventExtraProvider
|
||||
*/
|
||||
public function testLocateFromEventExtra( $message, $expect, array $extra, array $keys ) {
|
||||
$event = $this->mockEchoEvent();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getExtra' )
|
||||
->will( $this->returnValue( $extra ) );
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getExtraParam' )
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getExtra' )
|
||||
->willReturn( $extra );
|
||||
$event->method( 'getExtraParam' )
|
||||
->will( $this->returnValueMap( self::arrayToValueMap( $extra ) ) );
|
||||
|
||||
$users = EchoUserLocator::locateFromEventExtra( $event, $keys );
|
||||
|
@ -258,9 +249,4 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected function mockEchoEvent() {
|
||||
return $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
|
10
tests/phpunit/cache/TitleLocalCacheTest.php
vendored
10
tests/phpunit/cache/TitleLocalCacheTest.php
vendored
|
@ -21,7 +21,7 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
$cache->add( 9 );
|
||||
|
||||
// Resolutions should be batched
|
||||
$cache->expects( $this->exactly( 1 ) )->method( 'resolve' )
|
||||
$cache->expects( $this->once() )->method( 'resolve' )
|
||||
->with( [ 1, 9 ] )->willReturn( [] );
|
||||
|
||||
// Trigger
|
||||
|
@ -38,7 +38,7 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
$cachePriv->targets->set( $res1['id'], $res1['title'] );
|
||||
// Second title not in internal cache, resolves from db.
|
||||
$res2 = $this->insertPage( 'EchoTitleLocalCacheTest_testGet2' );
|
||||
$cache->expects( $this->exactly( 1 ) )->method( 'resolve' )
|
||||
$cache->expects( $this->once() )->method( 'resolve' )
|
||||
->with( [ $res2['id'] ] )
|
||||
->willReturn( [ $res2['id'] => $res2['title'] ] );
|
||||
|
||||
|
@ -68,7 +68,7 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertNull( $cache->get( 1 ), 'Cache was cleared' );
|
||||
|
||||
// Lookups batch was cleared
|
||||
$cache->expects( $this->exactly( 1 ) )->method( 'resolve' )
|
||||
$cache->expects( $this->once() )->method( 'resolve' )
|
||||
->with( [ 4 ] )
|
||||
->willReturn( [] );
|
||||
$cache->add( 4 );
|
||||
|
@ -79,9 +79,7 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
* @return Title
|
||||
*/
|
||||
protected function mockTitle() {
|
||||
$title = $this->getMockBuilder( Title::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$title = $this->createMock( Title::class );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
|
|
@ -82,12 +82,9 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
] );
|
||||
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getType' )
|
||||
->will( $this->returnValue( 'unit-test' ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getType' )
|
||||
->willReturn( 'unit-test' );
|
||||
|
||||
if ( $setup !== null ) {
|
||||
$setup( $this, $event );
|
||||
|
@ -159,12 +156,9 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
] );
|
||||
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getType' )
|
||||
->will( $this->returnValue( 'unit-test' ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getType' )
|
||||
->willReturn( 'unit-test' );
|
||||
|
||||
$result = EchoNotificationController::getUsersToNotifyForEvent( $event );
|
||||
$ids = [];
|
||||
|
@ -175,12 +169,9 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testDoesNotDeliverDisabledEvent() {
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'isEnabledEvent' )
|
||||
->will( $this->returnValue( false ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'isEnabledEvent' )
|
||||
->willReturn( false );
|
||||
// Assume it would have to check the event type to
|
||||
// determine how to deliver
|
||||
$event->expects( $this->never() )
|
||||
|
@ -265,18 +256,15 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testEnqueueEvent() {
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getExtraParam' )
|
||||
->will( $this->returnValue( null ) );
|
||||
$event->expects( $this->exactly( 1 ) )
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->willReturn( null );
|
||||
$event->expects( $this->once() )
|
||||
->method( 'getTitle' )
|
||||
->will( $this->returnValue( Title::newFromText( 'test-title' ) ) );
|
||||
$event->expects( $this->exactly( 1 ) )
|
||||
->willReturn( Title::newFromText( 'test-title' ) );
|
||||
$event->expects( $this->once() )
|
||||
->method( 'getId' )
|
||||
->will( $this->returnValue( 42 ) );
|
||||
->willReturn( 42 );
|
||||
EchoNotificationController::enqueueEvent( $event );
|
||||
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
|
||||
$queues = $jobQueueGroup->getQueuesWithJobs();
|
||||
|
@ -291,11 +279,8 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
$queueGroup = $this->getServiceContainer()->getJobQueueGroup();
|
||||
$this->assertCount( 0, $queueGroup->getQueuesWithJobs() );
|
||||
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getExtraParam' )
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->will( $this->returnValueMap(
|
||||
[
|
||||
[ 'delay', null, 120 ],
|
||||
|
@ -303,12 +288,11 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
[ 'rootJobTimestamp', null, wfTimestamp() ]
|
||||
]
|
||||
) );
|
||||
$event->expects( $this->exactly( 1 ) )
|
||||
$event->expects( $this->once() )
|
||||
->method( 'getTitle' )
|
||||
->will( $this->returnValue( Title::newFromText( 'test-title' ) ) );
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getId' )
|
||||
->will( $this->returnValue( 42 ) );
|
||||
->willReturn( Title::newFromText( 'test-title' ) );
|
||||
$event->method( 'getId' )
|
||||
->willReturn( 42 );
|
||||
EchoNotificationController::enqueueEvent( $event );
|
||||
|
||||
$this->assertCount( 0, $queueGroup->getQueuesWithJobs() );
|
||||
|
@ -318,11 +302,8 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
$rootJobTimestamp = wfTimestamp();
|
||||
MWTimestamp::setFakeTime( 0 );
|
||||
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getExtraParam' )
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->will( $this->returnValueMap(
|
||||
[
|
||||
[ 'delay', null, 10 ],
|
||||
|
@ -330,9 +311,9 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
[ 'rootJobTimestamp', null, $rootJobTimestamp ]
|
||||
]
|
||||
) );
|
||||
$event->expects( $this->exactly( 1 ) )
|
||||
$event->expects( $this->once() )
|
||||
->method( 'getId' )
|
||||
->will( $this->returnValue( 42 ) );
|
||||
->willReturn( 42 );
|
||||
|
||||
$params = EchoNotificationController::getEventParams( $event );
|
||||
$expectedParams = [
|
||||
|
@ -355,7 +336,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
public function testIsPageLinkedTitleMutedByUser(
|
||||
Title $title, User $user, UserOptionsLookup $userOptionsLookup, $expected ): void {
|
||||
$wrapper = TestingAccessWrapper::newFromClass( EchoNotificationController::class );
|
||||
$wrapper->mutedPageLinkedTitlesCache = $this->getMapCacheLruMock();
|
||||
$wrapper->mutedPageLinkedTitlesCache = $this->createMock( MapCacheLRU::class );
|
||||
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
|
@ -388,29 +369,19 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
private function getMockTitle( int $articleID ) {
|
||||
$title = $this->getMockBuilder( Title::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$title = $this->createMock( Title::class );
|
||||
$title->method( 'getArticleID' )
|
||||
->willReturn( $articleID );
|
||||
return $title;
|
||||
}
|
||||
|
||||
private function getMockUser() {
|
||||
$user = $this->getMockBuilder( User::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$user = $this->createMock( User::class );
|
||||
$user->method( 'getId' )
|
||||
->willReturn( 456 );
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function getMapCacheLruMock() {
|
||||
return $this->getMockBuilder( MapCacheLRU::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getUserOptionsLookupMock( $mutedTitlePreferences = [] ) {
|
||||
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class );
|
||||
$userOptionsLookupMock->method( 'getOption' )
|
||||
|
|
|
@ -17,11 +17,10 @@ class EchoContainmentSetTest extends MediaWikiIntegrationTestCase {
|
|||
public function testAddTitlesFromUserOption(
|
||||
$prefData, string $contains, bool $expected
|
||||
) {
|
||||
$user = $this->getDefaultUserMock();
|
||||
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class );
|
||||
$userOptionsLookupMock->method( 'getOption' )->willReturn( $prefData );
|
||||
$this->setService( 'UserOptionsLookup', $userOptionsLookupMock );
|
||||
$containmentSet = new EchoContainmentSet( $user );
|
||||
$containmentSet = new EchoContainmentSet( $this->createMock( User::class ) );
|
||||
$containmentSet->addTitleIDsFromUserOption( 'preference-name' );
|
||||
$this->assertSame( $expected, $containmentSet->contains( $contains ) );
|
||||
}
|
||||
|
@ -52,10 +51,4 @@ class EchoContainmentSetTest extends MediaWikiIntegrationTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
private function getDefaultUserMock() {
|
||||
return $this->getMockBuilder( User::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class EchoServicesTest extends MediaWikiIntegrationTestCase {
|
|||
/** @var EchoServices */
|
||||
private $echoServices;
|
||||
|
||||
public function setUp(): void {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->echoServices = EchoServices::getInstance();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use Wikimedia\TestingAccessWrapper;
|
|||
*/
|
||||
class SubscriptionManagerTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
public function setUp(): void {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->tablesUsed[] = 'echo_push_subscription';
|
||||
$this->tablesUsed[] = 'echo_push_provider';
|
||||
|
|
|
@ -79,12 +79,9 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
* @return EchoEvent
|
||||
*/
|
||||
protected function mockEchoEvent() {
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'toDbArray' )
|
||||
->will( $this->returnValue( [] ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
@ -94,12 +91,9 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
* @return MWEchoDbFactory
|
||||
*/
|
||||
protected function mockMWEchoDbFactory( $dbResult ) {
|
||||
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbFactory->expects( $this->any() )
|
||||
->method( 'getEchoDb' )
|
||||
->will( $this->returnValue( $this->mockDb( $dbResult ) ) );
|
||||
$dbFactory = $this->createMock( MWEchoDbFactory::class );
|
||||
$dbFactory->method( 'getEchoDb' )
|
||||
->willReturn( $this->mockDb( $dbResult ) );
|
||||
|
||||
return $dbFactory;
|
||||
}
|
||||
|
@ -116,18 +110,14 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
'selectRow' => ''
|
||||
];
|
||||
$db = $this->createMock( IDatabase::class );
|
||||
$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( 'selectRow' )
|
||||
->will( $this->returnValue( $dbResult['selectRow'] ) );
|
||||
$db->method( 'insert' )
|
||||
->willReturn( $dbResult['insert'] );
|
||||
$db->method( 'insertId' )
|
||||
->willReturn( $dbResult['insertId'] );
|
||||
$db->method( 'select' )
|
||||
->willReturn( $dbResult['select'] );
|
||||
$db->method( 'selectRow' )
|
||||
->willReturn( $dbResult['selectRow'] );
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
|
|
@ -155,38 +155,38 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
->method( 'delete' )
|
||||
->withConsecutive(
|
||||
[
|
||||
$this->equalTo( 'echo_notification' ),
|
||||
$this->equalTo( [ 'notification_user' => 1, 'notification_event' => [ 1, 2, 3, 5 ] ] ),
|
||||
'echo_notification',
|
||||
[ 'notification_user' => 1, 'notification_event' => [ 1, 2, 3, 5 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_notification' ),
|
||||
$this->equalTo( [ 'notification_user' => 1, 'notification_event' => [ 8, 13, 21, 34 ] ] ),
|
||||
'echo_notification',
|
||||
[ 'notification_user' => 1, 'notification_event' => [ 8, 13, 21, 34 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_event' ),
|
||||
$this->equalTo( [ 'event_id' => [ 13, 21 ] ] ),
|
||||
'echo_event',
|
||||
[ 'event_id' => [ 13, 21 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_target_page' ),
|
||||
$this->equalTo( [ 'etp_event' => [ 13, 21 ] ] ),
|
||||
'echo_target_page',
|
||||
[ 'etp_event' => [ 13, 21 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_notification' ),
|
||||
$this->equalTo( [ 'notification_user' => 1, 'notification_event' => [ 55, 89 ] ] ),
|
||||
'echo_notification',
|
||||
[ 'notification_user' => 1, 'notification_event' => [ 55, 89 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_event' ),
|
||||
$this->equalTo( [ 'event_id' => [ 55 ] ] ),
|
||||
'echo_event',
|
||||
[ 'event_id' => [ 55 ] ],
|
||||
$this->anything()
|
||||
],
|
||||
[
|
||||
$this->equalTo( 'echo_target_page' ),
|
||||
$this->equalTo( [ 'etp_event' => [ 55 ] ] ),
|
||||
'echo_target_page',
|
||||
[ 'etp_event' => [ 55 ] ],
|
||||
$this->anything()
|
||||
]
|
||||
)
|
||||
|
@ -201,12 +201,9 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
* @return User
|
||||
*/
|
||||
protected function mockUser() {
|
||||
$user = $this->getMockBuilder( User::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$user->expects( $this->any() )
|
||||
->method( 'getID' )
|
||||
->will( $this->returnValue( 1 ) );
|
||||
$user = $this->createMock( User::class );
|
||||
$user->method( 'getID' )
|
||||
->willReturn( 1 );
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
@ -216,12 +213,9 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
* @return EchoNotification
|
||||
*/
|
||||
protected function mockEchoNotification() {
|
||||
$event = $this->getMockBuilder( EchoNotification::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'toDbArray' )
|
||||
->will( $this->returnValue( [] ) );
|
||||
$event = $this->createMock( EchoNotification::class );
|
||||
$event->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
@ -233,12 +227,9 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
protected function mockMWEchoDbFactory( $dbResultOrMockDb ) {
|
||||
$mockDb = is_array( $dbResultOrMockDb ) ? $this->mockDb( $dbResultOrMockDb ) : $dbResultOrMockDb;
|
||||
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbFactory->expects( $this->any() )
|
||||
->method( 'getEchoDb' )
|
||||
->will( $this->returnValue( $mockDb ) );
|
||||
$dbFactory = $this->createMock( MWEchoDbFactory::class );
|
||||
$dbFactory->method( 'getEchoDb' )
|
||||
->willReturn( $mockDb );
|
||||
|
||||
return $dbFactory;
|
||||
}
|
||||
|
@ -257,20 +248,15 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
];
|
||||
|
||||
$db = $this->createMock( IDatabase::class );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'insert' )
|
||||
->will( $this->returnValue( $dbResult['insert'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'select' )
|
||||
->will( $this->returnValue( $dbResult['select'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'delete' )
|
||||
->will( $this->returnValue( $dbResult['delete'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'selectRow' )
|
||||
->will( $this->returnValue( $dbResult['selectRow'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'onTransactionCommitOrIdle' )
|
||||
$db->method( 'insert' )
|
||||
->willReturn( $dbResult['insert'] );
|
||||
$db->method( 'select' )
|
||||
->willReturn( $dbResult['select'] );
|
||||
$db->method( 'delete' )
|
||||
->willReturn( $dbResult['delete'] );
|
||||
$db->method( 'selectRow' )
|
||||
->willReturn( $dbResult['selectRow'] );
|
||||
$db->method( 'onTransactionCommitOrIdle' )
|
||||
->will( new EchoExecuteFirstArgumentStub );
|
||||
|
||||
return $db;
|
||||
|
|
|
@ -23,26 +23,28 @@ class NotificationServiceClientUnitTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function sendCheckEchoRequestsProvider(): array {
|
||||
$row = new stdClass();
|
||||
$row->eps_token = 'JKL123';
|
||||
$row->epp_name = 'fcm';
|
||||
$row->eps_data = null;
|
||||
$row->ept_text = null;
|
||||
$row->eps_updated = '2020-01-01 10:10:10';
|
||||
$row = (object)[
|
||||
'eps_token' => 'JKL123',
|
||||
'epp_name' => 'fcm',
|
||||
'ept_text' => null,
|
||||
'eps_updated' => '2020-01-01 10:10:10',
|
||||
];
|
||||
$subscriptions[] = Subscription::newFromRow( $row );
|
||||
|
||||
$row->eps_token = 'DEF456';
|
||||
$row->epp_name = 'fcm';
|
||||
$row->eps_data = null;
|
||||
$row->ept_text = null;
|
||||
$row->eps_updated = '2020-01-01 10:10:10';
|
||||
$row = (object)[
|
||||
'eps_token' => 'DEF456',
|
||||
'epp_name' => 'fcm',
|
||||
'ept_text' => null,
|
||||
'eps_updated' => '2020-01-01 10:10:10',
|
||||
];
|
||||
$subscriptions[] = Subscription::newFromRow( $row );
|
||||
|
||||
$row->eps_token = 'GHI789';
|
||||
$row->epp_name = 'apns';
|
||||
$row->eps_data = null;
|
||||
$row->ept_text = 'test';
|
||||
$row->eps_updated = '2020-01-01 10:10:10';
|
||||
$row = (object)[
|
||||
'eps_token' => 'GHI789',
|
||||
'epp_name' => 'apns',
|
||||
'ept_text' => 'test',
|
||||
'eps_updated' => '2020-01-01 10:10:10',
|
||||
];
|
||||
$subscriptions[] = Subscription::newFromRow( $row );
|
||||
|
||||
return [
|
||||
|
|
|
@ -7,12 +7,13 @@ use Wikimedia\Timestamp\ConvertibleTimestamp;
|
|||
class SubscriptionTest extends MediaWikiUnitTestCase {
|
||||
|
||||
public function testNewFromRow(): void {
|
||||
$row = new stdClass();
|
||||
$row->eps_token = 'AABC123';
|
||||
$row->epp_name = 'fcm';
|
||||
$row->eps_data = null;
|
||||
$row->ept_text = null;
|
||||
$row->eps_updated = '2020-01-01 10:10:10';
|
||||
$row = (object)[
|
||||
'eps_token' => 'AABC123',
|
||||
'epp_name' => 'fcm',
|
||||
'eps_data' => null,
|
||||
'ept_text' => null,
|
||||
'eps_updated' => '2020-01-01 10:10:10',
|
||||
];
|
||||
|
||||
$subscription = Subscription::newFromRow( $row );
|
||||
$this->assertSame( 'AABC123', $subscription->getToken() );
|
||||
|
@ -23,12 +24,13 @@ class SubscriptionTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testNewFromRowWithTopic(): void {
|
||||
$row = new stdClass();
|
||||
$row->eps_token = 'DEF456';
|
||||
$row->epp_name = 'apns';
|
||||
$row->eps_data = null;
|
||||
$row->ept_text = 'test';
|
||||
$row->eps_updated = '2020-01-01 10:10:10';
|
||||
$row = (object)[
|
||||
'eps_token' => 'DEF456',
|
||||
'epp_name' => 'apns',
|
||||
'eps_data' => null,
|
||||
'ept_text' => 'test',
|
||||
'eps_updated' => '2020-01-01 10:10:10',
|
||||
];
|
||||
|
||||
$subscription = Subscription::newFromRow( $row );
|
||||
$this->assertSame( 'DEF456', $subscription->getToken() );
|
||||
|
|
|
@ -112,12 +112,9 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase {
|
|||
* @return User
|
||||
*/
|
||||
protected function mockUser() {
|
||||
$user = $this->getMockBuilder( User::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$user->expects( $this->any() )
|
||||
->method( 'getID' )
|
||||
->will( $this->returnValue( 1 ) );
|
||||
$user = $this->createMock( User::class );
|
||||
$user->method( 'getID' )
|
||||
->willReturn( 1 );
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
@ -128,12 +125,9 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase {
|
|||
* @return MWEchoDbFactory
|
||||
*/
|
||||
protected function mockMWEchoDbFactory( array $dbResult = [] ) {
|
||||
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbFactory->expects( $this->any() )
|
||||
->method( 'getEchoDb' )
|
||||
->will( $this->returnValue( $this->mockDb( $dbResult ) ) );
|
||||
$dbFactory = $this->createMock( MWEchoDbFactory::class );
|
||||
$dbFactory->method( 'getEchoDb' )
|
||||
->willReturn( $this->mockDb( $dbResult ) );
|
||||
|
||||
return $dbFactory;
|
||||
}
|
||||
|
@ -157,18 +151,14 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase {
|
|||
'selectRowCount' => '',
|
||||
];
|
||||
$db = $this->createMock( IDatabase::class );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'update' )
|
||||
->will( $this->returnValue( $dbResult['update'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'select' )
|
||||
->will( $this->returnValue( $dbResult['select'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'selectRow' )
|
||||
->will( $this->returnValue( $dbResult['selectRow'] ) );
|
||||
$db->expects( $this->any() )
|
||||
->method( 'selectRowCount' )
|
||||
->will( $this->returnValue( $dbResult['selectRowCount'] ) );
|
||||
$db->method( 'update' )
|
||||
->willReturn( $dbResult['update'] );
|
||||
$db->method( 'select' )
|
||||
->willReturn( $dbResult['select'] );
|
||||
$db->method( 'selectRow' )
|
||||
->willReturn( $dbResult['selectRow'] );
|
||||
$db->method( 'selectRowCount' )
|
||||
->willReturn( $dbResult['selectRowCount'] );
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
|
|
@ -36,18 +36,13 @@ class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
|
|||
* @return 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 ) );
|
||||
$target = $this->createMock( EchoTargetPage::class );
|
||||
$target->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
$target->method( 'getPageId' )
|
||||
->willReturn( 2 );
|
||||
$target->method( 'getEventId' )
|
||||
->willReturn( 3 );
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
@ -58,12 +53,9 @@ class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
|
|||
* @return MWEchoDbFactory
|
||||
*/
|
||||
protected function mockMWEchoDbFactory( $dbResult ) {
|
||||
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbFactory->expects( $this->any() )
|
||||
->method( 'getEchoDb' )
|
||||
->will( $this->returnValue( $this->mockDb( $dbResult ) ) );
|
||||
$dbFactory = $this->createMock( MWEchoDbFactory::class );
|
||||
$dbFactory->method( 'getEchoDb' )
|
||||
->willReturn( $this->mockDb( $dbResult ) );
|
||||
|
||||
return $dbFactory;
|
||||
}
|
||||
|
@ -81,18 +73,14 @@ class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
|
|||
'delete' => ''
|
||||
];
|
||||
$db = $this->createMock( IDatabase::class );
|
||||
$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'] ) );
|
||||
$db->method( 'insert' )
|
||||
->willReturn( $dbResult['insert'] );
|
||||
$db->method( 'insertId' )
|
||||
->willReturn( $dbResult['insertId'] );
|
||||
$db->method( 'select' )
|
||||
->willReturn( $dbResult['select'] );
|
||||
$db->method( 'delete' )
|
||||
->willReturn( $dbResult['delete'] );
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
|
|
@ -64,12 +64,9 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|||
* @return Title
|
||||
*/
|
||||
protected function mockTitle( $pageId ) {
|
||||
$event = $this->getMockBuilder( Title::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getArticleID' )
|
||||
->will( $this->returnValue( $pageId ) );
|
||||
$event = $this->createMock( Title::class );
|
||||
$event->method( 'getArticleID' )
|
||||
->willReturn( $pageId );
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
@ -79,12 +76,9 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|||
* @return EchoEvent
|
||||
*/
|
||||
protected function mockEchoEvent( $eventId = 1 ) {
|
||||
$event = $this->getMockBuilder( EchoEvent::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$event->expects( $this->any() )
|
||||
->method( 'getId' )
|
||||
->will( $this->returnValue( $eventId ) );
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event->method( 'getId' )
|
||||
->willReturn( $eventId );
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue