Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
runSingleTask example
parent::
__construct
(
)
;
}
protected
function
configure
(
)
: void
{
$this
->
addArgument
(
'taskName', InputArgument::REQUIRED, 'Scheduled task name like log_entry.cleanup'
)
;
}
protected
function
execute
(
InputInterface
$input
, OutputInterface
$output
)
: int
{
$this
->taskRunner->
runSingleTask
(
$input
->
getArgument
(
'taskName'
)
, Context::
createDefaultContext
(
)
)
;
return
self::SUCCESS;
}
}
class
TaskRunnerTest
extends
TestCase
{
public
function
testNonExistingTask
(
)
: void
{
/** @var StaticEntityRepository<ScheduledTaskCollection> $scheduledTaskRepository */
$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
(
)
)
;