Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
RouteEventSubscriber example
$request
=
new
Request
(
)
;
$request
->attributes->
set
(
'_route', 'frontend.home.page'
)
;
$event
=
new
RequestEvent
(
$this
->
createMock
(
Kernel::
class
)
,
$request
, HttpKernelInterface::MAIN_REQUEST
)
;
$listener
=
$this
->
getMockBuilder
(
CallableClass::
class
)
->
getMock
(
)
;
$listener
->
expects
(
static
::
once
(
)
)
->
method
(
'__invoke'
)
;
$dispatcher
=
new
EventDispatcher
(
)
;
$dispatcher
->
addListener
(
'frontend.home.page.request',
$listener
)
;
$subscriber
=
new
RouteEventSubscriber
(
$dispatcher
)
;
$subscriber
->
request
(
$event
)
;
}
public
function
testResponseEvent
(
)
: void
{
$request
=
new
Request
(
)
;
$request
->attributes->
set
(
'_route', 'frontend.home.page'
)
;
$event
=
new
ResponseEvent
(
$this
->
createMock
(
Kernel::
class
)
,
$request
, HttpKernelInterface::MAIN_REQUEST,
new
Response
(
)
)
;
$listener
=
$this
->
getMockBuilder
(
CallableClass::
class
)
->
getMock
(
)
;