Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AnEnvelopeStamp example
$this
->serializer
->
method
(
'decode'
)
->
with
(
[
'foo' => 'ba'
]
)
->
willReturn
(
$envelopeDecoded
)
;
$this
->serializeTransport->
send
(
$envelope
)
;
$this
->
assertSame
(
[
$envelopeDecoded
]
,
$this
->serializeTransport->
get
(
)
)
;
}
public
function
testAcknowledgeSameMessageWithDifferentStamps
(
)
{
$envelope1
=
new
Envelope
(
new
\
stdClass
(
)
,
[
new
AnEnvelopeStamp
(
)
]
)
;
$envelope1
=
$this
->transport->
send
(
$envelope1
)
;
$envelope2
=
new
Envelope
(
new
\
stdClass
(
)
,
[
new
AnEnvelopeStamp
(
)
]
)
;
$envelope2
=
$this
->transport->
send
(
$envelope2
)
;
$this
->
assertSame
(
[
$envelope1
,
$envelope2
]
,
$this
->transport->
get
(
)
)
;
$this
->transport->
ack
(
$envelope1
->
with
(
new
AnEnvelopeStamp
(
)
)
)
;
$this
->
assertSame
(
[
$envelope2
]
,
$this
->transport->
get
(
)
)
;
$this
->transport->
reject
(
$envelope2
->
with
(
new
AnEnvelopeStamp
(
)
)
)
;
$this
->
assertSame
(
[
]
,
$this
->transport->
get
(
)
)
;
}
public
function
testAck
(
)
{
$firstMiddleware
,
$secondMiddleware
,
]
)
;
$bus
->
dispatch
(
$message
)
;
}
public
function
testThatAMiddlewareCanAddSomeStampsToTheEnvelope
(
)
{
$message
=
new
DummyMessage
(
'Hello'
)
;
$envelope
=
new
Envelope
(
$message
,
[
new
ReceivedStamp
(
'transport'
)
]
)
;
$envelopeWithAnotherStamp
=
$envelope
->
with
(
new
AnEnvelopeStamp
(
)
)
;
$firstMiddleware
=
$this
->
createMock
(
MiddlewareInterface::
class
)
;
$firstMiddleware
->
expects
(
$this
->
once
(
)
)
->
method
(
'handle'
)
->
with
(
$envelope
,
$this
->
anything
(
)
)
->
willReturnCallback
(
fn
(
$envelope
,
$stack
)
=>
$stack
->
next
(
)
->
handle
(
$envelope
->
with
(
new
AnEnvelopeStamp
(
)
)
,
$stack
)
)
;
$secondMiddleware
=
$this
->
createMock
(
MiddlewareInterface::
class
)
;
$secondMiddleware
->
expects
(
$this
->
once
(
)
)
->
method
(
'handle'
)
->
with
(
$envelopeWithAnotherStamp
,
$this
->
anything
(
)
)
'caller' =>
[
'name' => 'TestTracesWithHandleTraitAction.php',
'file'
=>
(
new
\
ReflectionClass
(
TestTracesWithHandleTraitAction::
class
)
)
->
getFileName
(
)
,
'line'
=>
(
new
\
ReflectionMethod
(
TestTracesWithHandleTraitAction::
class
, '__invoke'
)
)
->
getStartLine
(
)
+ 2,
]
,
]
,
$actualTracedMessage
)
;
}
public
function
testItTracesDispatchWithEnvelope
(
)
{
$message
=
new
DummyMessage
(
'Hello'
)
;
$envelope
=
(
new
Envelope
(
$message
)
)
->
with
(
$stamp
=
new
AnEnvelopeStamp
(
)
)
;
$bus
=
$this
->
createMock
(
MessageBusInterface::
class
)
;
$bus
->
expects
(
$this
->
once
(
)
)
->
method
(
'dispatch'
)
->
with
(
$envelope
)
->
willReturn
(
$envelope
)
;
$traceableBus
=
new
TraceableMessageBus
(
$bus
)
;
$line
= __LINE__ + 1;
$traceableBus
->
dispatch
(
$envelope
)
;
$this
->
assertCount
(
1,
$tracedMessages
=
$traceableBus
->
getDispatchedMessages
(
)
)
;
$actualTracedMessage
=
$tracedMessages
[
0
]
;
unset
(
$actualTracedMessage
[
'callTime'
]
)
; // don't check, too variable
$this
->
assertEquals
(
[