Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
FlowLogEvent example
public
function
testDispatchSkipTrigger
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
$context
->
addState
(
'skipTriggerFlow'
)
;
$order
=
new
OrderEntity
(
)
;
$event
=
new
CheckoutOrderPlacedEvent
(
$context
,
$order
,
Defaults::SALES_CHANNEL_TYPE_STOREFRONT
)
;
$flowLogEvent
=
new
FlowLogEvent
(
FlowLogEvent::NAME,
$event
)
;
$this
->dispatcher->
expects
(
static
::
exactly
(
2
)
)
->
method
(
'dispatch'
)
->
willReturnOnConsecutiveCalls
(
$event
,
$flowLogEvent
)
;
$this
->flowDispatcher->
dispatch
(
$event
)
;
}
public
function
testDispatchWithoutFlowLoader
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
$order
=
new
OrderEntity
(
)
;
$connection
->
executeStatement
(
'DELETE FROM `log_entry`'
)
;
}
public
function
testWriteFlowEvents
(
)
: void
{
$handler
=
new
TestHandler
(
)
;
$logger
=
new
Logger
(
'testlogger',
[
$handler
]
)
;
$service
=
new
LoggingService
(
'test',
$logger
)
;
$service
->
logFlowEvent
(
new
FlowLogEvent
(
TestFlowBusinessEvent::EVENT_NAME,
new
TestFlowBusinessEvent
(
$this
->context
)
)
)
;
$records
=
$handler
->
getRecords
(
)
;
static
::
assertCount
(
1,
$records
)
;
$testRecord
=
$records
[
0
]
;
static
::
assertEquals
(
TestFlowBusinessEvent::EVENT_NAME,
$testRecord
->message
)
;
static
::
assertEquals
(
'test',
$testRecord
->context
[
'environment'
]
)
;
static
::
assertEquals
(
Level::Debug,
$testRecord
->level
)
;
static
::
assertEmpty
(
$testRecord
->context
[
'additionalData'
]
)
;
}
public
function
dispatch
(
object
$event
, ?string
$eventName
= null
)
: object
{
$event
=
$this
->dispatcher->
dispatch
(
$event
,
$eventName
)
;
if
(
!
$event
instanceof FlowEventAware
)
{
return
$event
;
}
$flowLogEvent
=
new
FlowLogEvent
(
FlowLogEvent::NAME,
$event
)
;
$this
->dispatcher->
dispatch
(
$flowLogEvent
,
$flowLogEvent
->
getName
(
)
)
;
if
(
(
$event
instanceof StoppableEventInterface &&
$event
->
isPropagationStopped
(
)
)
||
$event
->
getContext
(
)
->
hasState
(
Context::SKIP_TRIGGER_FLOW
)
)
{
return
$event
;
}
$storableFlow
=
$this
->flowFactory->
create
(
$event
)
;
$this
->
callFlowExecutor
(
$storableFlow
)
;