mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-18 02:00:53 +00:00
Fixes for PHPUnit 6
Bug: T192167 Change-Id: I354077e8e44cfea3e75219d6701a4f9e11d4c70a
This commit is contained in:
parent
3eb7c9b976
commit
b72a95b5c0
|
@ -34,7 +34,9 @@ class EventLoggerFactoryTest extends MediaWikiTestCase {
|
||||||
* @covers \Popups\EventLogging\MWEventLogger::__construct
|
* @covers \Popups\EventLogging\MWEventLogger::__construct
|
||||||
*/
|
*/
|
||||||
public function testReturnsMWEventWhenEventLoggingIsAvailable() {
|
public function testReturnsMWEventWhenEventLoggingIsAvailable() {
|
||||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
$mock = $this->getMockBuilder( ExtensionRegistry::class )
|
||||||
|
->setMethods( [ 'isLoaded' ] )
|
||||||
|
->getMock();
|
||||||
$mock->expects( $this->once() )
|
$mock->expects( $this->once() )
|
||||||
->method( 'isLoaded' )
|
->method( 'isLoaded' )
|
||||||
->with( 'EventLogging' )
|
->with( 'EventLogging' )
|
||||||
|
@ -51,7 +53,9 @@ class EventLoggerFactoryTest extends MediaWikiTestCase {
|
||||||
* @covers ::get
|
* @covers ::get
|
||||||
*/
|
*/
|
||||||
public function testReturnsMWEventWhenEventLoggingIsNotAvailable() {
|
public function testReturnsMWEventWhenEventLoggingIsNotAvailable() {
|
||||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
$mock = $this->getMockBuilder( ExtensionRegistry::class )
|
||||||
|
->setMethods( [ 'isLoaded' ] )
|
||||||
|
->getMock();
|
||||||
$mock->expects( $this->once() )
|
$mock->expects( $this->once() )
|
||||||
->method( 'isLoaded' )
|
->method( 'isLoaded' )
|
||||||
->with( 'EventLogging' )
|
->with( 'EventLogging' )
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* @ingroup extensions
|
* @ingroup extensions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls;
|
||||||
use Popups\PopupsContext;
|
use Popups\PopupsContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,10 +158,12 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
] );
|
] );
|
||||||
$returnValues = [ $textExtracts, $pageImages ];
|
$returnValues = [ $textExtracts, $pageImages ];
|
||||||
|
|
||||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
$mock = $this->getMockBuilder( ExtensionRegistry::class )
|
||||||
|
->setMethods( [ 'isLoaded' ] )
|
||||||
|
->getMock();
|
||||||
$mock->expects( $this->any() )
|
$mock->expects( $this->any() )
|
||||||
->method( 'isLoaded' )
|
->method( 'isLoaded' )
|
||||||
->will( new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $returnValues ) );
|
->will( new ConsecutiveCalls( $returnValues ) );
|
||||||
$context = $this->getContext( $mock );
|
$context = $this->getContext( $mock );
|
||||||
$this->assertSame( $expected,
|
$this->assertSame( $expected,
|
||||||
$context->areDependenciesMet(),
|
$context->areDependenciesMet(),
|
||||||
|
@ -274,7 +277,7 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
* @covers ::logUserDisabledPagePreviewsEvent
|
* @covers ::logUserDisabledPagePreviewsEvent
|
||||||
*/
|
*/
|
||||||
public function testLogsEvent() {
|
public function testLogsEvent() {
|
||||||
$loggerMock = $this->getMock( \Popups\EventLogging\EventLogger::class );
|
$loggerMock = $this->createMock( \Popups\EventLogging\EventLogger::class );
|
||||||
$loggerMock->expects( $this->once() )
|
$loggerMock->expects( $this->once() )
|
||||||
->method( 'log' );
|
->method( 'log' );
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* @ingroup extensions
|
* @ingroup extensions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Popups\PopupsGadgetsIntegration;
|
use Popups\PopupsGadgetsIntegration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,10 +53,12 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $gadgetsEnabled
|
* @param bool $gadgetsEnabled
|
||||||
* @return PHPUnit_Framework_MockObject_MockObject|ExtensionRegistry
|
* @return MockObject|ExtensionRegistry
|
||||||
*/
|
*/
|
||||||
private function getExtensionRegistryMock( $gadgetsEnabled ) {
|
private function getExtensionRegistryMock( $gadgetsEnabled ) {
|
||||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
$mock = $this->getMockBuilder( ExtensionRegistry::class )
|
||||||
|
->setMethods( [ 'isLoaded' ] )
|
||||||
|
->getMock();
|
||||||
$mock->expects( $this->any() )
|
$mock->expects( $this->any() )
|
||||||
->method( 'isLoaded' )
|
->method( 'isLoaded' )
|
||||||
->with( 'Gadgets' )
|
->with( 'Gadgets' )
|
||||||
|
@ -64,7 +67,7 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return PHPUnit_Framework_MockObject_MockObject|Config
|
* @return MockObject|Config
|
||||||
*/
|
*/
|
||||||
private function getConfigMock() {
|
private function getConfigMock() {
|
||||||
$mock = $this->getMockBuilder( 'Config' )
|
$mock = $this->getMockBuilder( 'Config' )
|
||||||
|
@ -102,7 +105,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
$user = $this->getTestUser()->getUser();
|
$user = $this->getTestUser()->getUser();
|
||||||
|
|
||||||
$gadgetRepoMock = $this->getMock( GadgetRepo::class, [ 'getGadgetIds', 'getGadget' ] );
|
$gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class )
|
||||||
|
->setMethods( [ 'getGadgetIds', 'getGadget' ] )
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$gadgetRepoMock->expects( $this->once() )
|
$gadgetRepoMock->expects( $this->once() )
|
||||||
->method( 'getGadgetIds' )
|
->method( 'getGadgetIds' )
|
||||||
|
@ -130,8 +135,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
->with( $user )
|
->with( $user )
|
||||||
->willReturn( self::GADGET_ENABLED );
|
->willReturn( self::GADGET_ENABLED );
|
||||||
|
|
||||||
$gadgetRepoMock = $this->getMock( GadgetRepo::class,
|
$gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class )
|
||||||
[ 'getGadgetIds', 'getGadget' ] );
|
->setMethods( [ 'getGadgetIds', 'getGadget' ] )
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$gadgetRepoMock->expects( $this->once() )
|
$gadgetRepoMock->expects( $this->once() )
|
||||||
->method( 'getGadgetIds' )
|
->method( 'getGadgetIds' )
|
||||||
|
@ -155,8 +161,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
$user = $this->getTestUser()->getUser();
|
$user = $this->getTestUser()->getUser();
|
||||||
|
|
||||||
$gadgetRepoMock = $this->getMock( GadgetRepo::class,
|
$gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class )
|
||||||
[ 'getGadgetIds', 'getGadget' ] );
|
->setMethods( [ 'getGadgetIds', 'getGadget' ] )
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$gadgetRepoMock->expects( $this->once() )
|
$gadgetRepoMock->expects( $this->once() )
|
||||||
->method( 'getGadgetIds' )
|
->method( 'getGadgetIds' )
|
||||||
|
@ -198,8 +205,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase {
|
||||||
->method( 'isEnabled' )
|
->method( 'isEnabled' )
|
||||||
->willReturn( self::GADGET_ENABLED );
|
->willReturn( self::GADGET_ENABLED );
|
||||||
|
|
||||||
$gadgetRepoMock = $this->getMock( GadgetRepo::class,
|
$gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class )
|
||||||
[ 'getGadgetIds', 'getGadget' ] );
|
->setMethods( [ 'getGadgetIds', 'getGadget' ] )
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$gadgetRepoMock->expects( $this->once() )
|
$gadgetRepoMock->expects( $this->once() )
|
||||||
->method( 'getGadgetIds' )
|
->method( 'getGadgetIds' )
|
||||||
|
|
|
@ -190,11 +190,14 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
* @covers ::onBeforePageDisplay
|
* @covers ::onBeforePageDisplay
|
||||||
*/
|
*/
|
||||||
public function testOnBeforePageDisplayWhenDependenciesAreNotMet() {
|
public function testOnBeforePageDisplayWhenDependenciesAreNotMet() {
|
||||||
$skinMock = $this->getMock( Skin::class );
|
$skinMock = $this->createMock( Skin::class );
|
||||||
$outPageMock = $this->getMock( OutputPage::class, [ 'addModules' ], [], '', false );
|
$outPageMock = $this->getMockBuilder( OutputPage::class )
|
||||||
|
->setMethods( [ 'addModules' ] )
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
$outPageMock->expects( $this->never() )
|
$outPageMock->expects( $this->never() )
|
||||||
->method( 'addModules' );
|
->method( 'addModules' );
|
||||||
$loggerMock = $this->getMock( \Psr\Log\LoggerInterface::class );
|
$loggerMock = $this->createMock( \Psr\Log\LoggerInterface::class );
|
||||||
$loggerMock->expects( $this->once() )
|
$loggerMock->expects( $this->once() )
|
||||||
->method( 'error' );
|
->method( 'error' );
|
||||||
|
|
||||||
|
@ -233,15 +236,12 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
*/
|
*/
|
||||||
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
||||||
$isCodeLoaded, $isTitleBlacklisted ) {
|
$isCodeLoaded, $isTitleBlacklisted ) {
|
||||||
$skinMock = $this->getMock( Skin::class );
|
$skinMock = $this->createMock( Skin::class );
|
||||||
|
|
||||||
$outPageMock = $this->getMock(
|
$outPageMock = $this->getMockBuilder( OutputPage::class )
|
||||||
OutputPage::class,
|
->setMethods( [ 'addModules' ] )
|
||||||
[ 'addModules' ],
|
->disableOriginalConstructor()
|
||||||
[],
|
->getMock();
|
||||||
'',
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
$outPageMock->expects( $isCodeLoaded ? $this->once() : $this->never() )
|
$outPageMock->expects( $isCodeLoaded ? $this->once() : $this->never() )
|
||||||
->method( 'addModules' )
|
->method( 'addModules' )
|
||||||
|
|
Loading…
Reference in a new issue