mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-04 04:09:00 +00:00
5941ef476c
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
88 lines
1.8 KiB
PHP
88 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers EchoTargetPage
|
|
*/
|
|
class EchoTargetPageTest extends MediaWikiTestCase {
|
|
|
|
public function testCreate() {
|
|
$this->assertNull(
|
|
EchoTargetPage::create(
|
|
$this->mockTitle( 0 ),
|
|
$this->mockEchoEvent()
|
|
)
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
|
EchoTargetPage::class,
|
|
EchoTargetPage::create(
|
|
$this->mockTitle( 1 ),
|
|
$this->mockEchoEvent()
|
|
)
|
|
);
|
|
}
|
|
|
|
public function testNewFromRow() {
|
|
$row = (object)[
|
|
'etp_page' => 2,
|
|
'etp_event' => 3
|
|
];
|
|
$obj = EchoTargetPage::newFromRow( $row );
|
|
$this->assertInstanceOf( EchoTargetPage::class, $obj );
|
|
|
|
return $obj;
|
|
}
|
|
|
|
public function testNewFromRowWithException() {
|
|
$row = (object)[
|
|
'etp_event' => 3
|
|
];
|
|
$this->expectException( MWException::class );
|
|
EchoTargetPage::newFromRow( $row );
|
|
}
|
|
|
|
/**
|
|
* @depends testNewFromRow
|
|
*/
|
|
public function testToDbArray( $obj ) {
|
|
$row = $obj->toDbArray();
|
|
$this->assertTrue( is_array( $row ) );
|
|
|
|
// Not very common to assert that a field does _not_ exist
|
|
// but since we are explicitly removing it, it seems to make sense.
|
|
$this->assertArrayNotHasKey( 'etp_user', $row );
|
|
|
|
$this->assertArrayHasKey( 'etp_page', $row );
|
|
$this->assertArrayHasKey( 'etp_event', $row );
|
|
}
|
|
|
|
/**
|
|
* Mock object of Title
|
|
*/
|
|
protected function mockTitle( $pageId ) {
|
|
$event = $this->getMockBuilder( Title::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$event->expects( $this->any() )
|
|
->method( 'getArticleID' )
|
|
->will( $this->returnValue( $pageId ) );
|
|
|
|
return $event;
|
|
}
|
|
|
|
/**
|
|
* Mock object of EchoEvent
|
|
*/
|
|
protected function mockEchoEvent( $eventId = 1 ) {
|
|
$event = $this->getMockBuilder( EchoEvent::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$event->expects( $this->any() )
|
|
->method( 'getId' )
|
|
->will( $this->returnValue( $eventId ) );
|
|
|
|
return $event;
|
|
}
|
|
|
|
}
|