Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
collectSessionUsage example
$requestStack
->
push
(
new
Request
(
)
)
;
$requestStack
->
push
(
$request
)
;
$requestStack
->
push
(
$subRequest
=
new
Request
(
)
)
;
$subRequest
->
setSession
(
$session
)
;
$collector
=
$this
->
createMock
(
RequestDataCollector::
class
)
;
$collector
->
expects
(
$this
->
once
(
)
)
->
method
(
'collectSessionUsage'
)
;
$container
=
new
Container
(
)
;
$container
->
set
(
'request_stack',
$requestStack
)
;
$container
->
set
(
'session_collector',
$collector
->
collectSessionUsage
(
...
)
)
;
$this
->
expectException
(
UnexpectedSessionUsageException::
class
)
;
(
new
SessionListener
(
$container
, true
)
)
->
onSessionUsage
(
)
;
}
public
function
testSessionUsageCallbackWhenNoDebug
(
)
{
$session
=
$this
->
createMock
(
Session::
class
)
;
$session
->
method
(
'isStarted'
)
->
willReturn
(
true
)
;
$session
->
expects
(
$this
->
exactly
(
0
)
)
->
method
(
'save'
)
;
$cookie
=
$this
->
getCookieByName
(
$response
, 'sf_redirect'
)
;
$this
->
assertNull
(
$cookie
->
getValue
(
)
)
;
}
public
function
testItCollectsTheSessionTraceProperly
(
)
{
$collector
=
new
RequestDataCollector
(
)
;
$request
=
$this
->
createRequest
(
)
;
// RequestDataCollectorTest doesn't implement SessionInterface or SessionBagInterface, therefore should do nothing.
$collector
->
collectSessionUsage
(
)
;
$collector
->
collect
(
$request
,
$this
->
createResponse
(
)
)
;
$this
->
assertSame
(
[
]
,
$collector
->
getSessionUsages
(
)
)
;
$collector
->
reset
(
)
;
$session
=
$this
->
createMock
(
SessionInterface::
class
)
;
$session
->
method
(
'getMetadataBag'
)
->
willReturnCallback
(
static
function
D
)
use
(
$collector
)
{
$collector
->
collectSessionUsage
(
)
;
return
new
MetadataBag
(
)
;
}
)
;