Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
cannotRenderView example
/** * @param array<string, mixed> $parameters */
protected
function
renderView
(
string
$view
, array
$parameters
=
[
]
)
: string
{
$view
=
$this
->
getTemplateFinder
(
)
->
find
(
$view
)
;
if
(
$this
->twig !== null
)
{
try
{
return
$this
->twig->
render
(
$view
,
$parameters
)
;
}
catch
(
LoaderError|RuntimeError|SyntaxError
$e
)
{
throw
StorefrontException::
cannotRenderView
(
$view
,
$e
->
getMessage
(
)
,
$parameters
)
;
}
}
throw
StorefrontException::
dontHaveTwigInjected
(
static
::
class
)
;
}
protected
function
getTemplateFinder
(
)
: TemplateFinder
{
return
$this
->container->
get
(
TemplateFinder::
class
)
;
}
class
StorefrontExceptionTest
extends
TestCase
{
public
function
testCannotRenderView
(
)
: void
{
$parameters
=
[
'param' => 'Param',
'context' => Context::
createDefaultContext
(
)
,
]
;
$res
= StorefrontException::
cannotRenderView
(
'test.html.twig', 'Error message',
$parameters
)
;
static
::
assertEquals
(
500,
$res
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
'STOREFRONT__CAN_NOT_RENDER_VIEW',
$res
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Can not render test.html.twig view: Error message with these parameters: {"param":"Param"}',
$res
->
getMessage
(
)
)
;
}
public
function
testUnSupportStorefrontResponse
(
)
: void
{
$res
= StorefrontException::
unSupportStorefrontResponse
(
)
;
static
::
assertEquals
(
500,
$res
->
getStatusCode
(
)
)
;