Replace @expectedException with $this->expectException()

The @expectedException annotation got deprecated in PHPUnit 7.5, and
removed in PHPUnit 8.0. This was done because the annotation does have
two disadvantages:
* The class name is encoded in string, where it is not easy to find for
  all IDEs and tools.
* it did not allow to say exactly *when* the exception is expected.

Change-Id: I96862a18874f36355e817accd64d8703c1965c86
This commit is contained in:
Thiemo Kreuz 2019-02-19 11:39:13 +01:00 committed by Umherirrender
parent e649551e5e
commit 5941ef476c
4 changed files with 9 additions and 18 deletions

View file

@ -22,11 +22,9 @@ class EchoAbstractMapperTest extends MediaWikiTestCase {
return [ 'mapper' => $mapper, 'property' => $property ];
}
/**
* @expectedException MWException
*/
public function testAttachListenerWithException() {
$mapper = new EchoAbstractMapperStub();
$this->expectException( MWException::class );
$mapper->attachListener( 'nonExistingMethod', 'key_a', function () {
} );
}
@ -45,13 +43,13 @@ class EchoAbstractMapperTest extends MediaWikiTestCase {
/**
* @depends testAttachListener
* @expectedException MWException
*/
public function testGetMethodListenersWithException( $data ) {
$mapper = $data['mapper'];
$property = $data['property'];
$listeners = $mapper->getMethodListeners( 'nonExistingMethod' );
$this->expectException( MWException::class );
$mapper->getMethodListeners( 'nonExistingMethod' );
}
/**

View file

@ -53,9 +53,6 @@ class EchoEventMapperTest extends MediaWikiTestCase {
$this->assertInstanceOf( EchoEvent::class, $res );
}
/**
* @expectedException MWException
*/
public function testUnsuccessfulFetchById() {
$eventMapper = new EchoEventMapper(
$this->mockMWEchoDbFactory(
@ -64,8 +61,8 @@ class EchoEventMapperTest extends MediaWikiTestCase {
]
)
);
$res = $eventMapper->fetchById( 1 );
$this->assertInstanceOf( 'EchoEvent', $res );
$this->expectException( MWException::class );
$eventMapper->fetchById( 1 );
}
/**

View file

@ -37,14 +37,12 @@ class EchoNotificationTest extends MediaWikiTestCase {
}
}
/**
* @expectedException MWException
*/
public function testNewFromRowWithException() {
$row = $this->mockNotificationRow();
// Provide an invalid event id
$row['notification_event'] = -1;
$noitf = EchoNotification::newFromRow( (object)$row );
$this->expectException( MWException::class );
EchoNotification::newFromRow( (object)$row );
}
/**

View file

@ -33,14 +33,12 @@ class EchoTargetPageTest extends MediaWikiTestCase {
return $obj;
}
/**
* @expectedException MWException
*/
public function testNewFromRowWithException() {
$row = (object)[
'etp_event' => 3
];
$this->assertInstanceOf( 'EchoTargetPage', EchoTargetPage::newFromRow( $row ) );
$this->expectException( MWException::class );
EchoTargetPage::newFromRow( $row );
}
/**