thumbnailNotSupported example



    public function testGeneratorThrowsExceptionIfFileIsNoImage(): void
    {
        $this->setFixtureContext($this->context);
        $media = $this->getPngWithFolder();

        $filePath = $this->urlGenerator->getRelativeMediaUrl($media);
        $this->getPublicFilesystem()->write($filePath, 'this is the content of the file, which is not a image');

        $this->expectException(MediaException::class);
        $this->expectExceptionMessage(MediaException::thumbnailNotSupported($media->getId())->getMessage());
        $this->thumbnailService->updateThumbnails(
            $media,
            $this->context,
            false
        );
    }

    public function testItUsesOriginalImageIfItsSmallerThanGeneratedThumbnail(): void
    {
        $this->setFixtureContext($this->context);
        $media = $this->getJpgWithFolder();

        
$folder = $this->mediaFolderRepository->search($criteria$context)->get($mediaFolderId);
        $media->setMediaFolder($folder);
    }

    private function getImageResource(MediaEntity $media): \GdImage
    {
        $filePath = $this->urlGenerator->getRelativeMediaUrl($media);
        /** @var string $file */
        $file = $this->getFileSystem($media)->read($filePath);
        $image = @imagecreatefromstring($file);
        if ($image === false) {
            throw MediaException::thumbnailNotSupported($media->getId());
        }

        if (\function_exists('exif_read_data')) {
            /** @var resource $stream */
            $stream = fopen('php://memory', 'r+b');

            try {
                // use in-memory stream to read the EXIF-metadata,                 // to avoid downloading the image twice from a remote filesystem                 fwrite($stream$file);
                rewind($stream);

                
static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_TYPE_NOT_LOADED, $exception->getErrorCode());
        static::assertEquals('Media type, for id media-id, not loaded', $exception->getMessage());
        static::assertEquals(['mediaId' => $mediaId]$exception->getParameters());
    }

    public function testThumbnailNotSupported(): void
    {
        $mediaId = 'media-id';

        $exception = MediaException::thumbnailNotSupported($mediaId);

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_FILE_NOT_SUPPORTED_FOR_THUMBNAIL, $exception->getErrorCode());
        static::assertEquals('The file for media object with id media-id is not supported for creating thumbnails.', $exception->getMessage());
        static::assertEquals(['mediaId' => $mediaId]$exception->getParameters());
    }

    public function testThumbnailCouldNotBeSaved(): void
    {
        $url = 'http://url';

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