mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 07:26:29 +00:00
33126b69aa
In preparation of Code Sniffer based updates. Change-Id: Id5d43332b44a37665d57dc24ef8c432bc65b2f6a
78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
|
|
class EchoAbstractMapperTest extends MediaWikiTestCase {
|
|
|
|
public function testAttachListener() {
|
|
$mapper = new EchoAbstractMapperStub();
|
|
$mapper->attachListener( 'testMethod', 'key_a', function () {
|
|
} );
|
|
|
|
$class = new ReflectionClass( 'EchoAbstractMapperStub' );
|
|
$property = $class->getProperty( 'listeners' );
|
|
$property->setAccessible( true );
|
|
$listeners = $property->getValue( $mapper );
|
|
|
|
$this->assertArrayHasKey( 'testMethod', $listeners );
|
|
$this->assertArrayHasKey( 'key_a', $listeners['testMethod'] );
|
|
$this->assertTrue( is_callable( $listeners['testMethod']['key_a'] ) );
|
|
|
|
return array( 'mapper' => $mapper, 'property' => $property );
|
|
}
|
|
|
|
/**
|
|
* @expectedException MWException
|
|
*/
|
|
public function testAttachListenerWithException() {
|
|
$mapper = new EchoAbstractMapperStub();
|
|
$mapper->attachListener( 'nonExistingMethod', 'key_a', function () {
|
|
} );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
*/
|
|
public function testGetMethodListeners( $data ) {
|
|
$mapper = $data['mapper'];
|
|
$property = $data['property'];
|
|
|
|
$listeners = $mapper->getMethodListeners( 'testMethod' );
|
|
$this->assertArrayHasKey( 'key_a', $listeners );
|
|
$this->assertTrue( is_callable( $listeners['key_a'] ) );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
* @expectedException MWException
|
|
*/
|
|
public function testGetMethodListenersWithException( $data ) {
|
|
$mapper = $data['mapper'];
|
|
$property = $data['property'];
|
|
|
|
$listeners = $mapper->getMethodListeners( 'nonExistingMethod' );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
*/
|
|
public function testDetachListener( $data ) {
|
|
$mapper = $data['mapper'];
|
|
$property = $data['property'];
|
|
|
|
$mapper->detachListener( 'testMethod', 'key_a' );
|
|
$listeners = $property->getValue( $mapper );
|
|
$this->assertArrayHasKey( 'testMethod', $listeners );
|
|
$this->assertTrue( !isset( $listeners['testMethod']['key_a'] ) );
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Create a stub class for testing the abstract class
|
|
*/
|
|
class EchoAbstractMapperStub extends EchoAbstractMapper {
|
|
|
|
public function testMethod() {
|
|
}
|
|
|
|
}
|