mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-18 10:52:27 +00:00
baf711c3c5
Bug: T328220 Change-Id: I97ea68525392e921b970d15b5d5ffd9c89bae452
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Notifications\Mapper\AbstractMapper;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Notifications\Mapper\AbstractMapper
|
|
*/
|
|
class AbstractMapperTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @return array [ 'mapper' => AbstractMapper, 'property' => ReflectionProperty ]
|
|
*/
|
|
public function testAttachListener() {
|
|
$mapper = new EchoAbstractMapperStub();
|
|
$mapper->attachListener( 'testMethod', 'key_a', static function () {
|
|
} );
|
|
|
|
$class = new ReflectionClass( EchoAbstractMapperStub::class );
|
|
$property = $class->getProperty( 'listeners' );
|
|
$property->setAccessible( true );
|
|
$listeners = $property->getValue( $mapper );
|
|
|
|
$this->assertArrayHasKey( 'testMethod', $listeners );
|
|
$this->assertArrayHasKey( 'key_a', $listeners['testMethod'] );
|
|
$this->assertIsCallable( $listeners['testMethod']['key_a'] );
|
|
|
|
return [ 'mapper' => $mapper, 'property' => $property ];
|
|
}
|
|
|
|
public function testAttachListenerWithException() {
|
|
$mapper = new EchoAbstractMapperStub();
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$mapper->attachListener( 'nonExistingMethod', 'key_a', static function () {
|
|
} );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
*/
|
|
public function testGetMethodListeners( $data ) {
|
|
/** @var AbstractMapper $mapper */
|
|
$mapper = $data['mapper'];
|
|
|
|
$listeners = $mapper->getMethodListeners( 'testMethod' );
|
|
$this->assertArrayHasKey( 'key_a', $listeners );
|
|
$this->assertIsCallable( $listeners['key_a'] );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
*/
|
|
public function testGetMethodListenersWithException( $data ) {
|
|
/** @var AbstractMapper $mapper */
|
|
$mapper = $data['mapper'];
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$mapper->getMethodListeners( 'nonExistingMethod' );
|
|
}
|
|
|
|
/**
|
|
* @depends testAttachListener
|
|
*/
|
|
public function testDetachListener( $data ) {
|
|
/** @var AbstractMapper $mapper */
|
|
$mapper = $data['mapper'];
|
|
/** @var ReflectionProperty $property */
|
|
$property = $data['property'];
|
|
|
|
$mapper->detachListener( 'testMethod', 'key_a' );
|
|
$listeners = $property->getValue( $mapper );
|
|
$this->assertArrayHasKey( 'testMethod', $listeners );
|
|
$this->assertTrue( !isset( $listeners['testMethod']['key_a'] ) );
|
|
}
|
|
|
|
}
|