Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
invalidFile example
static
::
assertEquals
(
Response::HTTP_NOT_FOUND,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_NOT_FOUND,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Media for id media-id not found.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'mediaId' =>
$mediaId
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testInvalidFile
(
)
: void
{
$cause
= 'cause';
$exception
= MediaException::
invalidFile
(
$cause
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_INVALID_FILE,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Provided file is invalid: cause.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'cause' =>
$cause
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testEmptyMediaFilename
(
)
: void
{
$exception
= MediaException::
emptyMediaFilename
(
)
;
$mediaId
,
$context
)
;
}
)
;
return
$mediaId
;
}
private
function
checkValidFile
(
UploadedFile
$file
)
: void
{
if
(
!
$file
->
isValid
(
)
)
{
throw
MediaException::
invalidFile
(
$file
->
getErrorMessage
(
)
)
;
}
if
(
preg_match
(
'/.+\.ph(p([3457s]|-s)?|t|tml)/',
$file
->
getFilename
(
)
)
)
{
throw
MediaException::
illegalFileName
(
$file
->
getFilename
(
)
, 'contains PHP related file extension'
)
;
}
}
}