3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 use MediaWiki\DomainEvent\DomainEventSource
;
20 use MediaWiki\DomainEvent\EventDispatchEngine
;
21 use MediaWiki\Registration\ExtensionRegistry
;
22 use Wikimedia\TestingAccessWrapper
;
25 * Validates event subscriber registration of all loaded extensions and skins.
28 class EventSubscriptionTest
extends MediaWikiIntegrationTestCase
{
30 private function newSpyEvenSource( &$events ): DomainEventSource
{
31 $services = $this->getServiceContainer();
33 $dispatcher = $this->getMockBuilder( EventDispatchEngine
::class )
34 ->setConstructorArgs( [
35 $services->getObjectFactory(),
36 $services->getHookContainer()
38 ->onlyMethods( [ 'registerListener' ] )
41 $dispatcher->method( 'registerListener' )
42 ->willReturnCallback( static function ( $event ) use ( &$events ) {
49 public static function provideEventSubscriberSpecs() {
50 $subscriberSpecs = ExtensionRegistry
::getInstance()
51 ->getAttribute( 'DomainEventSubscribers' );
53 foreach ( $subscriberSpecs as $spec ) {
59 * This checks that domain event subscribers actually subscriber for the
60 * events that they declare in the extension registration.
61 * @dataProvider provideEventSubscriberSpecs
63 public function testPassesValidation( $spec ) {
64 $this->assertArrayHasKey( 'events', $spec );
65 $expected = $spec['events'];
68 $source = $this->newSpyEvenSource( $actual );
69 $source = TestingAccessWrapper
::newFromObject( $source );
71 $source->applySubscriberSpec( $spec );
73 $path = $spec['extensionPath'];
74 $this->assertEquals( $expected, $actual, "Events subscribed to in $path" );