Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
LazyLoadingFragmentHandler example
$renderer
=
$this
->
createMock
(
FragmentRendererInterface::
class
)
;
$renderer
->
expects
(
$this
->
once
(
)
)
->
method
(
'getName'
)
->
willReturn
(
'foo'
)
;
$renderer
->
expects
(
$this
->
any
(
)
)
->
method
(
'render'
)
->
willReturn
(
new
Response
(
)
)
;
$requestStack
=
$this
->
createMock
(
RequestStack::
class
)
;
$requestStack
->
expects
(
$this
->
any
(
)
)
->
method
(
'getCurrentRequest'
)
->
willReturn
(
Request::
create
(
'/'
)
)
;
$container
=
$this
->
createMock
(
ContainerInterface::
class
)
;
$container
->
expects
(
$this
->
once
(
)
)
->
method
(
'has'
)
->
with
(
'foo'
)
->
willReturn
(
true
)
;
$container
->
expects
(
$this
->
once
(
)
)
->
method
(
'get'
)
->
willReturn
(
$renderer
)
;
$handler
=
new
LazyLoadingFragmentHandler
(
$container
,
$requestStack
, false
)
;
$handler
->
render
(
'/foo', 'foo'
)
;
// second call should not lazy-load anymore (see once() above on the get() method)
$handler
->
render
(
'/foo', 'foo'
)
;
}
}