Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4075808
DomainEventIngressTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DomainEventIngressTest.php
View Options
<?php
namespace
MediaWiki\Tests\DomainEvent
;
use
MediaWiki\DomainEvent\DomainEventIngress
;
use
MediaWiki\DomainEvent\DomainEventSource
;
use
MediaWiki\DomainEvent\EventDispatchEngine
;
use
MediaWikiUnitTestCase
;
use
Wikimedia\ObjectFactory\ObjectFactory
;
use
Wikimedia\Services\ServiceContainer
;
/**
* @covers \MediaWiki\DomainEvent\DomainEventIngress
*/
class
DomainEventIngressTest
extends
MediaWikiUnitTestCase
{
private
function
newSpyEventSource
(
&
$trace
):
DomainEventSource
{
$objectFactory
=
new
ObjectFactory
(
$this
->
createNoOpMock
(
ServiceContainer
::
class
)
);
$dispatcher
=
$this
->
getMockBuilder
(
EventDispatchEngine
::
class
)
->
setConstructorArgs
(
[
$objectFactory
]
)
->
onlyMethods
(
[
'registerListener'
]
)
->
getMock
();
$dispatcher
->
method
(
'registerListener'
)
->
willReturnCallback
(
static
function
(
...
$args
)
use
(
&
$trace
)
{
$trace
[]
=
$args
;
}
);
return
$dispatcher
;
}
public
function
testAutoSubscribe_constructor
()
{
$trace
=
[];
$source
=
$this
->
newSpyEventSource
(
$trace
);
// Pass the list of events as a constructor parameter
$subscriber
=
new
class
extends
DomainEventIngress
{
public
function
handleFooEvent
()
{
// no-op
}
// Check that the AfterCommit suffix is allowed, for backwards compat
public
function
handleBarEventAfterCommit
()
{
// no-op
}
public
function
handleXyzzyEvent
()
{
// no-op
}
};
$subscriber
->
initSubscriber
(
[
'events'
=>
[
'Foo'
,
'Bar'
]
]
);
$subscriber
->
registerListeners
(
$source
);
$this
->
assertSame
(
[
[
'Foo'
,
[
$subscriber
,
'handleFooEvent'
,
],
[],
],
[
'Bar'
,
[
$subscriber
,
'handleBarEventAfterCommit'
,
],
[],
],
],
$trace
);
}
public
function
testAutoSubscribe_init
()
{
$trace
=
[];
$source
=
$this
->
newSpyEventSource
(
$trace
);
$events
=
[
'Foo'
,
'Bar'
];
// Pass nothing to the constructor, rely on initSubscriber()
$subscriber
=
new
class
()
extends
DomainEventIngress
{
public
function
handleFooEvent
()
{
// no-op
}
// Check that the AfterCommit suffix is allowed, for backwards compat
public
function
handleBarEventAfterCommit
()
{
// no-op
}
public
function
handleXyzzyEvent
()
{
// no-op
}
};
$subscriber
->
initSubscriber
(
[
'events'
=>
$events
]
);
$subscriber
->
registerListeners
(
$source
);
$this
->
assertSame
(
[
[
'Foo'
,
[
$subscriber
,
'handleFooEvent'
,
],
[],
],
[
'Bar'
,
[
$subscriber
,
'handleBarEventAfterCommit'
,
],
[],
],
],
$trace
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 17 2026, 19:24 (10 w, 11 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ec/4a/93b185d1d52b98fbc76534b61697
Default Alt Text
DomainEventIngressTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment