Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
invalidUrl example
private
function
getUrlFromRequest
(
Request
$request
)
: string
{
$url
=
(string)
$request
->request->
get
(
'url'
)
;
if
(
$url
=== ''
)
{
throw
MediaException::
missingUrlParameter
(
)
;
}
if
(
!
$this
->
isUrlValid
(
$url
)
)
{
throw
MediaException::
invalidUrl
(
$url
)
;
}
return
$url
;
}
/** * @throws MediaException * * @return resource */
private
function
openSourceFromUrl
(
string
$url
)
{
$exception
= MediaException::
invalidContentLength
(
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_INVALID_CONTENT_LENGTH,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Expected content-length did not match actual size.',
$exception
->
getMessage
(
)
)
;
}
public
function
testInvalidUrl
(
)
: void
{
$url
= 'http://invalid-url';
$exception
= MediaException::
invalidUrl
(
$url
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_INVALID_URL,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Provided URL "http://invalid-url" is invalid.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'url' =>
$url
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testIllegalUrl
(
)
: void
{
$url
= 'http://illegal-url';