Page MenuHomeWickedGov Phorge

MiddlewareChainTest.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

MiddlewareChainTest.php

<?php
/**
* @license GPL-2.0-or-later
* @file
*/
namespace MediaWiki\Tests\Integration\Notification;
use MediaWiki\MediaWikiServices;
use MediaWiki\Notification\MiddlewareException;
use MediaWiki\Notification\Notification;
use MediaWiki\Notification\NotificationMiddlewareInterface;
use MediaWiki\Notification\RecipientSet;
use MediaWiki\Registration\ExtensionRegistry;
use MediaWiki\User\UserIdentity;
use MediaWikiIntegrationTestCase;
use Wikimedia\ScopedCallback;
/**
* @group Mail
* @covers \MediaWiki\Notification\MiddlewareChain
*/
class MiddlewareChainTest extends MediaWikiIntegrationTestCase {
/**
* Test case when Middleware calls NotificationService::notify() to inject new notification
* This can cause endless loops where Middleware triggers a notification, that triggers the
* middleware again.
*
* @return void
*/
public function testMiddlewareCannotTriggerNotificationService() {
$this->expectException( MiddlewareException::class );
$scope = ExtensionRegistry::getInstance()->setAttributeForTest(
'NotificationMiddleware', [
[
"factory" => static function () {
return new class implements NotificationMiddlewareInterface {
public function handle( $batch, callable $next ): void {
MediaWikiServices::getInstance()
->getNotificationService()
->notify(
new Notification( "bad" ), new RecipientSet( [] )
);
$next();
}
};
},
],
]
);
$sut = MediaWikiServices::getInstance()->getNotificationService();
$user = $this->createMock( UserIdentity::class );
$sut->notify(
new Notification( "good" ), new RecipientSet( [ $user ] )
);
ScopedCallback::consume( $scope );
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 05:37 (2 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4d/22/3d3b869ca32c0d70b229f2856710
Default Alt Text
MiddlewareChainTest.php (1 KB)

Event Timeline