couldNotRenameFile example

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

    public function testCouldNotRenameFile(): void
    {
        $mediaId = 'media-id';
        $oldFileName = 'old-file-name';

        $exception = MediaException::couldNotRenameFile($mediaId$oldFileName);

        static::assertEquals(Response::HTTP_CONFLICT, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_COULD_NOT_RENAME_FILE, $exception->getErrorCode());
        static::assertEquals('Could not rename file for media with id: media-id. Rollback to filename: "old-file-name"', $exception->getMessage());
        static::assertEquals(['mediaId' => $mediaId, 'oldFileName' => $oldFileName]$exception->getParameters());
    }

    public function testEmptyMediaId(): void
    {
        $exception = MediaException::emptyMediaId();

        
$updatedMedia = clone $currentMedia;
        $updatedMedia->setFileName($destination);
        $updatedMedia->setUploadedAt(new \DateTime());

        try {
            $renamedFiles = $this->renameFile(
                $this->urlGenerator->getRelativeMediaUrl($currentMedia),
                $this->urlGenerator->getRelativeMediaUrl($updatedMedia),
                $this->getFileSystem($currentMedia)
            );
        } catch (\Exception) {
            throw MediaException::couldNotRenameFile($currentMedia->getId()(string) $currentMedia->getFileName());
        }

        foreach ($currentMedia->getThumbnails() ?? [] as $thumbnail) {
            try {
                $renamedFiles = [...$renamedFiles, ...$this->renameThumbnail($thumbnail$currentMedia$updatedMedia)];
            } catch (\Exception) {
                $this->rollbackRenameAction($currentMedia$renamedFiles);
            }
        }

        $updateData = [
            
static::assertTrue($this->getPublicFilesystem()->has($this->urlGenerator->getRelativeMediaUrl($updatedMedia)));

        static::assertFalse($this->getPublicFilesystem()->has($oldThumbnailPath));
        static::assertTrue($this->getPublicFilesystem()->has($this->urlGenerator->getRelativeThumbnailUrl($updatedMedia(new MediaThumbnailEntity())->assign(['width' => 100, 'height' => 100]))));
    }

    public function testRenameMediaMakesRollbackOnFailure(): void
    {
        $png = $this->getPng();

        $this->expectException(MediaException::class);
        $this->expectExceptionMessage(MediaException::couldNotRenameFile($png->getId()(string) $png->getFileName())->getMessage());

        $context = Context::createDefaultContext();
        $this->setFixtureContext($context);

        $collection = new MediaCollection([$png]);
        $searchResult = new EntitySearchResult('temp', 1, $collection, null, new Criteria()$context);

        $repositoryMock = $this->createMock(EntityRepository::class);
        $repositoryMock->expects(static::exactly(2))
            ->method('search')
            ->willReturn($searchResult);

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