fileSizeLimitExceeded example



            return $writtenBytes;
        }

        $writtenBytes = stream_copy_to_stream($sourceStream$destStream$maxFileSize, 0);
        if ($writtenBytes === false) {
            throw MediaException::cannotCopyMedia();
        }

        if ($writtenBytes === $maxFileSize) {
            throw MediaException::fileSizeLimitExceeded();
        }

        return $writtenBytes;
    }

    private function isUrlValid(string $url): bool
    {
        return (bool) filter_var($url, \FILTER_VALIDATE_URL) && $this->isProtocolAllowed($url);
    }

    private function isProtocolAllowed(string $url): bool
    {
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());
        static::assertEquals(MediaException::MEDIA_FILE_SIZE_LIMIT_EXCEEDED, $exception->getErrorCode());
        static::assertEquals('Source file exceeds maximum file size limit.', $exception->getMessage());
    }

    public function testMissingFileExtension(): void
    {
        $exception = MediaException::missingFileExtension();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        
Home | Imprint | This part of the site doesn't use cookies.