Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CacheItem example
static
::
assertCount
(
0,
$this
->eventDispatcher->
getEvents
(
)
)
;
}
public
function
testUninstallPlugin
(
)
: void
{
$pluginEntityMock
=
$this
->
getPluginEntityMock
(
)
;
$context
= Context::
createDefaultContext
(
)
;
$pluginEntityMock
->
setInstalledAt
(
new
\
DateTime
(
)
)
;
$pluginEntityMock
->
setActive
(
true
)
;
$this
->cacheItemPoolInterfaceMock->
method
(
'getItem'
)
->
willReturn
(
new
CacheItem
(
)
)
;
/** postInstall is called */
$this
->pluginMock->
expects
(
static
::
once
(
)
)
->
method
(
'uninstall'
)
;
$this
->pluginLifecycleService->
uninstallPlugin
(
$pluginEntityMock
,
$context
)
;
$returnedEvents
=
$this
->eventDispatcher->
getEvents
(
)
;
static
::
assertInstanceOf
(
PluginPreDeactivateEvent::
class
,
$returnedEvents
[
0
]
)
;
static
::
assertInstanceOf
(
PluginPostDeactivateEvent::
class
,
$returnedEvents
[
1
]
)
;
static
::
assertInstanceOf
(
PluginPreUninstallEvent::
class
,
$returnedEvents
[
2
]
)
;
$class
=
new
\
ReflectionClass
(
CacheItem::
class
)
;
$keyProp
=
$class
->
getProperty
(
'key'
)
;
$keyProp
->
setAccessible
(
true
)
;
$valueProp
=
$class
->
getProperty
(
'value'
)
;
$valueProp
->
setAccessible
(
true
)
;
$isHitProp
=
$class
->
getProperty
(
'isHit'
)
;
$isHitProp
->
setAccessible
(
true
)
;
$item
=
new
CacheItem
(
)
;
$keyProp
->
setValue
(
$item
,
$key
)
;
$valueProp
->
setValue
(
$item
,
$value
)
;
$isHitProp
->
setValue
(
$item
,
$isHit
)
;
return
$item
;
}
private
function
storefontSalesChannelCriteria
(
array
$ids
)
: Criteria
{
$criteria
=
new
Criteria
(
$ids
)
;
$criteria
->
addAssociation
(
'domains'
)
;
class
CacheStoreTest
extends
TestCase
{
public
function
testGetLock
(
)
: void
{
$request
=
new
Request
(
)
;
$cache
=
$this
->
createMock
(
TagAwareAdapterInterface::
class
)
;
$cache
->
expects
(
static
::
once
(
)
)
->
method
(
'hasItem'
)
->
willReturn
(
false
)
;
$item
=
new
CacheItem
(
)
;
$cache
->
expects
(
static
::
once
(
)
)
->
method
(
'getItem'
)
->
willReturn
(
$item
)
;
$cache
->
expects
(
static
::
once
(
)
)
->
method
(
'save'
)
->
with
(
$item
)
;
$store
=
new
CacheStore
(
$cache
,
$this
->
createMock
(
CacheStateValidator::
class
)
,
new
EventDispatcher
(
)
,
$this
->
createMock
(
AbstractCacheTracer::
class
)
,
new
HttpCacheKeyGenerator
(
'test',
new
EventDispatcher
(
)
,
[
]
)
,
$decorated
,
$requestStack
,
$cache
,
$this
->
createMock
(
MessageFormatterInterface::
class
)
,
'prod',
$connection
,
$localeCodeProvider
,
$snippetServiceMock
,
false
)
;
$item
=
new
CacheItem
(
)
;
$property
=
(
new
\
ReflectionClass
(
$item
)
)
->
getProperty
(
'isTaggable'
)
;
$property
->
setAccessible
(
true
)
;
$property
->
setValue
(
$item
, true
)
;
$cache
->
expects
(
$expectedCacheKey
?
static
::
once
(
)
:
static
::
never
(
)
)
->
method
(
'get'
)
->
willReturnCallback
(
function
Dstring
$key
, callable
$callback
)
use
(
$expectedCacheKey
,
$item
)
{
static
::
assertEquals
(
$expectedCacheKey
,
$key
)
;
/** @var callable(CacheItem): mixed $callback */
return
$callback
(
$item
)
;
}
)
;