Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
TestTask2Handler example
$scheduledTaskRepository
=
new
StaticEntityRepository
(
[
new
ScheduledTaskCollection
(
)
]
)
;
$taskRunner
=
new
TaskRunner
(
[
]
,
$scheduledTaskRepository
)
;
$this
->
expectException
(
MessageQueueException::
class
)
;
$this
->
expectExceptionMessage
(
'Cannot find scheduled task by name "non-existing-task"'
)
;
$taskRunner
->
runSingleTask
(
'non-existing-task', Context::
createDefaultContext
(
)
)
;
}
public
function
testRunTaskTriggersHandler
(
)
: void
{
$handler
=
new
TestTaskHandler
(
)
;
$handler2
=
new
TestTask2Handler
(
)
;
$invalid
=
$this
->
createMock
(
StaticEntityRepository::
class
)
;
$invalid
->
expects
(
static
::
never
(
)
)
->
method
(
static
::
anything
(
)
)
;
$taskRunner
=
new
TaskRunner
(
[
$handler
,
$handler2
,
$invalid
]
,
$this
->
getRepository
(
)
)
;
$taskRunner
->
runSingleTask
(
'task-id', Context::
createDefaultContext
(
)
)
;
static
::
assertTrue
(
$handler
->called
)
;
static
::
assertFalse
(
$handler2
->called
)
;
}
/** * @return StaticEntityRepository<ScheduledTaskCollection> */