Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
KernelPluginCollection example
private
bool
$initialized
= false;
/** * @internal */
public
function
__construct
(
private
readonly ClassLoader
$classLoader
,
?string
$pluginDir
= null
)
{
$this
->pluginDir =
$pluginDir
?? 'custom/plugins';
$this
->pluginInstances =
new
KernelPluginCollection
(
)
;
}
final
public
function
getPluginDir
(
string
$projectDir
)
: string
{
// absolute path
if
(
mb_strpos
(
$this
->pluginDir, '/'
)
=== 0
)
{
return
$this
->pluginDir;
}
return
$projectDir
. '/' .
$this
->pluginDir;
}
$kernelMock
=
$this
->
createMock
(
Kernel::
class
)
;
$pluginMock
=
$this
->
createMock
(
Plugin::
class
)
;
$activeReflection
=
new
\
ReflectionProperty
(
Plugin::
class
, 'active'
)
;
$activeReflection
->
setAccessible
(
true
)
;
$activeReflection
->
setValue
(
$pluginMock
, true
)
;
$pluginMock
->
method
(
'getPath'
)
->
willReturn
(
__DIR__ . '/fixtures/caseBundleLoadingWithPlugin/bundle'
)
;
$kernelPluginLoaderMock
=
$this
->
createMock
(
KernelPluginLoader::
class
)
;
$activeReflection
=
new
\
ReflectionProperty
(
KernelPluginLoader::
class
, 'pluginInstances'
)
;
$activeReflection
->
setAccessible
(
true
)
;
$activeReflection
->
setValue
(
$kernelPluginLoaderMock
,
new
KernelPluginCollection
(
[
$pluginMock
]
)
)
;
$kernelMock
->
expects
(
static
::
exactly
(
2
)
)
->
method
(
'getPluginLoader'
)
->
willReturn
(
$kernelPluginLoaderMock
)
;
$kernelMock
->
expects
(
static
::
exactly
(
1
)
)
->
method
(
'getBundles'
)
->
willReturn
(
[
$pluginMock
]
)
;