From b72a95b5c0fd260b4fdc44ef92219082c0ca7d1d Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sat, 5 Oct 2019 22:43:20 -0700 Subject: [PATCH] Fixes for PHPUnit 6 Bug: T192167 Change-Id: I354077e8e44cfea3e75219d6701a4f9e11d4c70a --- .../EventLogging/EventLoggerFactoryTest.php | 8 ++++-- tests/phpunit/PopupsContextTest.php | 9 ++++-- .../phpunit/PopupsGadgetsIntegrationTest.php | 28 ++++++++++++------- tests/phpunit/PopupsHooksTest.php | 22 +++++++-------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/tests/phpunit/EventLogging/EventLoggerFactoryTest.php b/tests/phpunit/EventLogging/EventLoggerFactoryTest.php index b54b82d0e..be918398f 100644 --- a/tests/phpunit/EventLogging/EventLoggerFactoryTest.php +++ b/tests/phpunit/EventLogging/EventLoggerFactoryTest.php @@ -34,7 +34,9 @@ class EventLoggerFactoryTest extends MediaWikiTestCase { * @covers \Popups\EventLogging\MWEventLogger::__construct */ public function testReturnsMWEventWhenEventLoggingIsAvailable() { - $mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] ); + $mock = $this->getMockBuilder( ExtensionRegistry::class ) + ->setMethods( [ 'isLoaded' ] ) + ->getMock(); $mock->expects( $this->once() ) ->method( 'isLoaded' ) ->with( 'EventLogging' ) @@ -51,7 +53,9 @@ class EventLoggerFactoryTest extends MediaWikiTestCase { * @covers ::get */ public function testReturnsMWEventWhenEventLoggingIsNotAvailable() { - $mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] ); + $mock = $this->getMockBuilder( ExtensionRegistry::class ) + ->setMethods( [ 'isLoaded' ] ) + ->getMock(); $mock->expects( $this->once() ) ->method( 'isLoaded' ) ->with( 'EventLogging' ) diff --git a/tests/phpunit/PopupsContextTest.php b/tests/phpunit/PopupsContextTest.php index 871b63dff..1dc72173d 100644 --- a/tests/phpunit/PopupsContextTest.php +++ b/tests/phpunit/PopupsContextTest.php @@ -19,6 +19,7 @@ * @ingroup extensions */ +use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls; use Popups\PopupsContext; /** @@ -157,10 +158,12 @@ class PopupsContextTest extends MediaWikiTestCase { ] ); $returnValues = [ $textExtracts, $pageImages ]; - $mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] ); + $mock = $this->getMockBuilder( ExtensionRegistry::class ) + ->setMethods( [ 'isLoaded' ] ) + ->getMock(); $mock->expects( $this->any() ) ->method( 'isLoaded' ) - ->will( new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $returnValues ) ); + ->will( new ConsecutiveCalls( $returnValues ) ); $context = $this->getContext( $mock ); $this->assertSame( $expected, $context->areDependenciesMet(), @@ -274,7 +277,7 @@ class PopupsContextTest extends MediaWikiTestCase { * @covers ::logUserDisabledPagePreviewsEvent */ public function testLogsEvent() { - $loggerMock = $this->getMock( \Popups\EventLogging\EventLogger::class ); + $loggerMock = $this->createMock( \Popups\EventLogging\EventLogger::class ); $loggerMock->expects( $this->once() ) ->method( 'log' ); diff --git a/tests/phpunit/PopupsGadgetsIntegrationTest.php b/tests/phpunit/PopupsGadgetsIntegrationTest.php index 1f3351599..ce43d7865 100644 --- a/tests/phpunit/PopupsGadgetsIntegrationTest.php +++ b/tests/phpunit/PopupsGadgetsIntegrationTest.php @@ -18,6 +18,7 @@ * @ingroup extensions */ +use PHPUnit\Framework\MockObject\MockObject; use Popups\PopupsGadgetsIntegration; /** @@ -52,10 +53,12 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { /** * @param bool $gadgetsEnabled - * @return PHPUnit_Framework_MockObject_MockObject|ExtensionRegistry + * @return MockObject|ExtensionRegistry */ private function getExtensionRegistryMock( $gadgetsEnabled ) { - $mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] ); + $mock = $this->getMockBuilder( ExtensionRegistry::class ) + ->setMethods( [ 'isLoaded' ] ) + ->getMock(); $mock->expects( $this->any() ) ->method( 'isLoaded' ) ->with( 'Gadgets' ) @@ -64,7 +67,7 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { } /** - * @return PHPUnit_Framework_MockObject_MockObject|Config + * @return MockObject|Config */ private function getConfigMock() { $mock = $this->getMockBuilder( 'Config' ) @@ -102,7 +105,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { $user = $this->getTestUser()->getUser(); - $gadgetRepoMock = $this->getMock( GadgetRepo::class, [ 'getGadgetIds', 'getGadget' ] ); + $gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class ) + ->setMethods( [ 'getGadgetIds', 'getGadget' ] ) + ->getMock(); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) @@ -130,8 +135,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { ->with( $user ) ->willReturn( self::GADGET_ENABLED ); - $gadgetRepoMock = $this->getMock( GadgetRepo::class, - [ 'getGadgetIds', 'getGadget' ] ); + $gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class ) + ->setMethods( [ 'getGadgetIds', 'getGadget' ] ) + ->getMock(); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) @@ -155,8 +161,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { $user = $this->getTestUser()->getUser(); - $gadgetRepoMock = $this->getMock( GadgetRepo::class, - [ 'getGadgetIds', 'getGadget' ] ); + $gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class ) + ->setMethods( [ 'getGadgetIds', 'getGadget' ] ) + ->getMock(); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) @@ -198,8 +205,9 @@ class PopupsGadgetsIntegrationTest extends MediaWikiTestCase { ->method( 'isEnabled' ) ->willReturn( self::GADGET_ENABLED ); - $gadgetRepoMock = $this->getMock( GadgetRepo::class, - [ 'getGadgetIds', 'getGadget' ] ); + $gadgetRepoMock = $this->getMockBuilder( GadgetRepo::class ) + ->setMethods( [ 'getGadgetIds', 'getGadget' ] ) + ->getMock(); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) diff --git a/tests/phpunit/PopupsHooksTest.php b/tests/phpunit/PopupsHooksTest.php index 06a4ab7ac..dbc494182 100644 --- a/tests/phpunit/PopupsHooksTest.php +++ b/tests/phpunit/PopupsHooksTest.php @@ -190,11 +190,14 @@ class PopupsHooksTest extends MediaWikiTestCase { * @covers ::onBeforePageDisplay */ public function testOnBeforePageDisplayWhenDependenciesAreNotMet() { - $skinMock = $this->getMock( Skin::class ); - $outPageMock = $this->getMock( OutputPage::class, [ 'addModules' ], [], '', false ); + $skinMock = $this->createMock( Skin::class ); + $outPageMock = $this->getMockBuilder( OutputPage::class ) + ->setMethods( [ 'addModules' ] ) + ->disableOriginalConstructor() + ->getMock(); $outPageMock->expects( $this->never() ) ->method( 'addModules' ); - $loggerMock = $this->getMock( \Psr\Log\LoggerInterface::class ); + $loggerMock = $this->createMock( \Psr\Log\LoggerInterface::class ); $loggerMock->expects( $this->once() ) ->method( 'error' ); @@ -233,15 +236,12 @@ class PopupsHooksTest extends MediaWikiTestCase { */ public function testOnBeforePageDisplay( $shouldSendModuleToUser, $isCodeLoaded, $isTitleBlacklisted ) { - $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( $isCodeLoaded ? $this->once() : $this->never() ) ->method( 'addModules' )