Fixes for PHPUnit 6

Bug: T192167
Change-Id: I354077e8e44cfea3e75219d6701a4f9e11d4c70a
This commit is contained in:
Max Semenik 2019-10-05 22:43:20 -07:00
parent 3eb7c9b976
commit b72a95b5c0
4 changed files with 41 additions and 26 deletions

View file

@ -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' )

View file

@ -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' );

View file

@ -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' )

View file

@ -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' )