invalidContentLength example

/** * @internal * * @covers \Shopware\Core\Content\Media\MediaException */
#[Package('buyers-experience')] class MediaExceptionTest extends TestCase
{
    public function testInvalidContentLength(): void
    {
        $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);

        
$inputStream = $request->getContent(true);
        $destStream = $this->openDestinationStream($fileName);

        try {
            $bytesWritten = $this->copyStreams($inputStream$destStream, 0);
        } finally {
            fclose($inputStream);
            fclose($destStream);
        }

        if ($expectedLength !== $bytesWritten) {
            throw MediaException::invalidContentLength();
        }

        return new MediaFile(
            $fileName,
            (string) mime_content_type($fileName),
            $extension,
            $bytesWritten,
            hash_file('md5', $fileName) ?: null
        );
    }

    
Home | Imprint | This part of the site doesn't use cookies.