Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
cannotCopyMedia example
/** * @param resource $sourceStream * @param resource $destStream */
private
function
copyStreams
(
$sourceStream
,
$destStream
, int
$maxFileSize
= 0
)
: int
{
if
(
$maxFileSize
=== 0
)
{
$writtenBytes
=
stream_copy_to_stream
(
$sourceStream
,
$destStream
)
;
if
(
$writtenBytes
=== false
)
{
throw
MediaException::
cannotCopyMedia
(
)
;
}
return
$writtenBytes
;
}
$writtenBytes
=
stream_copy_to_stream
(
$sourceStream
,
$destStream
,
$maxFileSize
, 0
)
;
if
(
$writtenBytes
=== false
)
{
throw
MediaException::
cannotCopyMedia
(
)
;
}
if
(
$writtenBytes
===
$maxFileSize
)
{
$exception
= MediaException::
cannotOpenSourceStreamToWrite
(
$fileName
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_CANNOT_OPEN_SOURCE_STREAM_TO_WRITE,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Cannot open source stream to write upload data: invalid-filename.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'fileName' =>
$fileName
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testCannotCopyMedia
(
)
: void
{
$exception
= MediaException::
cannotCopyMedia
(
)
;
static
::
assertEquals
(
Response::HTTP_CONFLICT,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_CANNOT_COPY_MEDIA,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Error while copying media from source.',
$exception
->
getMessage
(
)
)
;
}
public
function
testFileSizeLimitExceeded
(
)
: void
{
$exception
= MediaException::
fileSizeLimitExceeded
(
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;