Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getDep example
$initCounter
= 0;
$proxy
=
$this
->
createLazyProxy
(
TestClass::
class
,
function
D
)
use
(
&
$initCounter
)
{
++
$initCounter
;
return
new
TestClass
(
(object)
[
'hello' => 'world'
]
)
;
}
)
;
$this
->
assertInstanceOf
(
TestClass::
class
,
$proxy
)
;
$this
->
assertSame
(
0,
$initCounter
)
;
$this
->
assertFalse
(
$proxy
->
isLazyObjectInitialized
(
)
)
;
$dep1
=
$proxy
->
getDep
(
)
;
$this
->
assertTrue
(
$proxy
->
isLazyObjectInitialized
(
)
)
;
$this
->
assertSame
(
1,
$initCounter
)
;
$this
->
assertTrue
(
$proxy
->
resetLazyObject
(
)
)
;
$this
->
assertSame
(
1,
$initCounter
)
;
$dep2
=
$proxy
->
getDep
(
)
;
$this
->
assertSame
(
2,
$initCounter
)
;
$this
->
assertNotSame
(
$dep1
,
$dep2
)
;
}