Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
afterCategoryNotFound example
$exception
= CategoryException::
footerCategoryNotFoundForSalesChannel
(
$salesChannelName
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
CategoryException::FOOTER_CATEGORY_NOT_FOUND,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Footer category, for sales channel sales-channel-name, is not set',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'salesChannelName' =>
$salesChannelName
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testAfterCategoryNotFound
(
)
: void
{
$exception
= CategoryException::
afterCategoryNotFound
(
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
CategoryException::AFTER_CATEGORY_NOT_FOUND,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Category to insert after not found.',
$exception
->
getMessage
(
)
)
;
}
}
#[Package('content')]
class
CategoryNonExistentExceptionHandler
implements
ExceptionHandlerInterface
{
public
function
getPriority
(
)
: int
{
return
ExceptionHandlerInterface::PRIORITY_DEFAULT;
}
public
function
matchException
(
\Exception
$e
)
: ?\Exception
{
if
(
preg_match
(
'/SQLSTATE\[23000\]:.*1452 Cannot add or update a child row: a foreign key constraint fails.*category\.after_category_id/',
$e
->
getMessage
(
)
)
)
{
return
CategoryException::
afterCategoryNotFound
(
)
;
}
return
null;
}
}