Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
RoutableMessageBus example
$receiverLocator
=
$this
->
createMock
(
ContainerInterface::
class
)
;
$receiverLocator
->
expects
(
$this
->
once
(
)
)
->
method
(
'has'
)
->
with
(
'dummy-receiver'
)
->
willReturn
(
true
)
;
$receiverLocator
->
expects
(
$this
->
once
(
)
)
->
method
(
'get'
)
->
with
(
'dummy-receiver'
)
->
willReturn
(
$receiver
)
;
$bus
=
$this
->
createMock
(
MessageBusInterface::
class
)
;
$bus
->
expects
(
$this
->
once
(
)
)
->
method
(
'dispatch'
)
;
$busLocator
=
$this
->
createMock
(
ContainerInterface::
class
)
;
$busLocator
->
expects
(
$this
->
once
(
)
)
->
method
(
'has'
)
->
with
(
'dummy-bus'
)
->
willReturn
(
true
)
;
$busLocator
->
expects
(
$this
->
once
(
)
)
->
method
(
'get'
)
->
with
(
'dummy-bus'
)
->
willReturn
(
$bus
)
;
$command
=
new
ConsumeMessagesCommand
(
new
RoutableMessageBus
(
$busLocator
)
,
$receiverLocator
,
new
EventDispatcher
(
)
)
;
$application
=
new
Application
(
)
;
$application
->
add
(
$command
)
;
$tester
=
new
CommandTester
(
$application
->
get
(
'messenger:consume'
)
)
;
$tester
->
execute
(
[
'receivers' =>
[
'dummy-receiver'
]
,
'--limit' => 1,
]
)
;
$tester
->
assertCommandIsSuccessful
(
)
;
$this
->
assertStringContainsString
(
'[OK] Consuming messages from transport "dummy-receiver"',
$tester
->
getDisplay
(
)
)
;
}
$bus1
=
$this
->
createMock
(
MessageBusInterface::
class
)
;
$bus2
=
$this
->
createMock
(
MessageBusInterface::
class
)
;
$container
=
$this
->
createMock
(
ContainerInterface::
class
)
;
$container
->
expects
(
$this
->
once
(
)
)
->
method
(
'has'
)
->
with
(
'foo_bus'
)
->
willReturn
(
true
)
;
$container
->
expects
(
$this
->
once
(
)
)
->
method
(
'get'
)
->
willReturn
(
$bus2
)
;
$stamp
=
new
DelayStamp
(
5
)
;
$bus1
->
expects
(
$this
->
never
(
)
)
->
method
(
'dispatch'
)
;
$bus2
->
expects
(
$this
->
once
(
)
)
->
method
(
'dispatch'
)
->
with
(
$envelope
,
[
$stamp
]
)
->
willReturn
(
$envelope
)
;
$routableBus
=
new
RoutableMessageBus
(
$container
)
;
$this
->
assertSame
(
$envelope
,
$routableBus
->
dispatch
(
$envelope
,
[
$stamp
]
)
)
;
}
public
function
testItRoutesToDefaultBus
(
)
{
$envelope
=
new
Envelope
(
new
\
stdClass
(
)
)
;
$stamp
=
new
DelayStamp
(
5
)
;
$defaultBus
=
$this
->
createMock
(
MessageBusInterface::
class
)
;
$defaultBus
->
expects
(
$this
->
once
(
)
)
->
method
(
'dispatch'
)
->
with
(
$envelope
,
[
$stamp
]
)
->
willReturn
(
$envelope
)
;