2014-08-07 19:10:37 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
|
|
|
* @covers EchoAbstractMapper
|
|
|
|
*/
|
2014-08-07 19:10:37 +00:00
|
|
|
class EchoAbstractMapperTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testAttachListener() {
|
|
|
|
$mapper = new EchoAbstractMapperStub();
|
2015-10-01 13:48:52 +00:00
|
|
|
$mapper->attachListener( 'testMethod', 'key_a', function () {
|
|
|
|
} );
|
2014-08-07 19:10:37 +00:00
|
|
|
|
2019-02-19 10:35:54 +00:00
|
|
|
$class = new ReflectionClass( EchoAbstractMapperStub::class );
|
2014-08-07 19:10:37 +00:00
|
|
|
$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'] ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ 'mapper' => $mapper, 'property' => $property ];
|
2014-08-07 19:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAttachListenerWithException() {
|
|
|
|
$mapper = new EchoAbstractMapperStub();
|
2019-02-19 10:39:13 +00:00
|
|
|
$this->expectException( MWException::class );
|
2015-10-01 13:48:52 +00:00
|
|
|
$mapper->attachListener( 'nonExistingMethod', 'key_a', function () {
|
|
|
|
} );
|
2014-08-07 19:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public function testGetMethodListenersWithException( $data ) {
|
|
|
|
$mapper = $data['mapper'];
|
|
|
|
$property = $data['property'];
|
|
|
|
|
2019-02-19 10:39:13 +00:00
|
|
|
$this->expectException( MWException::class );
|
|
|
|
$mapper->getMethodListeners( 'nonExistingMethod' );
|
2014-08-07 19:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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'] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|