Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CacheClassMetadataFactory example
parent::
__construct
(
$phpArrayFile
)
;
$this
->loaders =
$loaders
;
}
protected
function
doWarmUp
(
string
$cacheDir
, ArrayAdapter
$arrayAdapter
)
: bool
{
if
(
!
$this
->loaders
)
{
return
true;
}
$metadataFactory
=
new
CacheClassMetadataFactory
(
new
ClassMetadataFactory
(
new
LoaderChain
(
$this
->loaders
)
)
,
$arrayAdapter
)
;
foreach
(
$this
->
extractSupportedLoaders
(
$this
->loaders
)
as
$loader
)
{
foreach
(
$loader
->
getMappedClasses
(
)
as
$mappedClass
)
{
try
{
$metadataFactory
->
getMetadataFor
(
$mappedClass
)
;
}
catch
(
AnnotationException
)
{
// ignore failing annotations
}
catch
(
\Exception
$e
)
{
$this
->
ignoreAutoloadException
(
$mappedClass
,
$e
)
;
}
}
}
public
function
testGetMetadataFor
(
)
{
$metadata
=
new
ClassMetadata
(
Dummy::
class
)
;
$decorated
=
$this
->
createMock
(
ClassMetadataFactoryInterface::
class
)
;
$decorated
->
expects
(
$this
->
once
(
)
)
->
method
(
'getMetadataFor'
)
->
willReturn
(
$metadata
)
;
$factory
=
new
CacheClassMetadataFactory
(
$decorated
,
new
ArrayAdapter
(
)
)
;
$this
->
assertEquals
(
$metadata
,
$factory
->
getMetadataFor
(
Dummy::
class
)
)
;
// The second call should retrieve the value from the cache
$this
->
assertEquals
(
$metadata
,
$factory
->
getMetadataFor
(
Dummy::
class
)
)
;
}
public
function
testHasMetadataFor
(
)
{
$decorated
=
$this
->
createMock
(
ClassMetadataFactoryInterface::
class
)
;
$decorated
->
expects
(
$this
->
once
(
)
)