Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
enableOptionalWarmers example
public
function
testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled
(
)
{
$warmer
=
$this
->
createMock
(
CacheWarmerInterface::
class
)
;
$warmer
->
expects
(
$this
->
never
(
)
)
->
method
(
'isOptional'
)
;
$warmer
->
expects
(
$this
->
once
(
)
)
->
method
(
'warmUp'
)
;
$aggregate
=
new
CacheWarmerAggregate
(
[
$warmer
]
)
;
$aggregate
->
enableOptionalWarmers
(
)
;
$aggregate
->
warmUp
(
__DIR__
)
;
}
public
function
testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled
(
)
{
$warmer
=
$this
->
createMock
(
CacheWarmerInterface::
class
)
;
$warmer
->
expects
(
$this
->
once
(
)
)
->
method
(
'isOptional'
)
->
willReturn
(
true
)
;
$warmer
}
protected
function
execute
(
InputInterface
$input
, OutputInterface
$output
)
: int
{
$io
=
new
SymfonyStyle
(
$input
,
$output
)
;
$kernel
=
$this
->
getApplication
(
)
->
getKernel
(
)
;
$io
->
comment
(
sprintf
(
'Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>',
$kernel
->
getEnvironment
(
)
,
var_export
(
$kernel
->
isDebug
(
)
, true
)
)
)
;
if
(
!
$input
->
getOption
(
'no-optional-warmers'
)
)
{
$this
->cacheWarmer->
enableOptionalWarmers
(
)
;
}
$preload
=
$this
->cacheWarmer->
warmUp
(
$cacheDir
=
$kernel
->
getContainer
(
)
->
getParameter
(
'kernel.cache_dir'
)
)
;
if
(
$preload
&&
file_exists
(
$preloadFile
=
$cacheDir
.'/'.
$kernel
->
getContainer
(
)
->
getParameter
(
'kernel.container_class'
)
.'.preload.php'
)
)
{
Preloader::
append
(
$preloadFile
,
$preload
)
;
}
$io
->
success
(
sprintf
(
'Cache for the "%s" environment (debug=%s) was successfully warmed.',
$kernel
->
getEnvironment
(
)
,
var_export
(
$kernel
->
isDebug
(
)
, true
)
)
)
;
return
0;
}