invalidBatchSize example

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

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_EMPTY_ID, $exception->getErrorCode());
        static::assertEquals('A media id must be provided.', $exception->getMessage());
    }

    public function testInvalidBatchSize(): void
    {
        $exception = MediaException::invalidBatchSize();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_INVALID_BATCH_SIZE, $exception->getErrorCode());
        static::assertEquals('Provided batch size is invalid.', $exception->getMessage());
    }

    public function testThumbnailAssociationNotLoaded(): void
    {
        $exception = MediaException::thumbnailAssociationNotLoaded();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        
$this->folderFilter = $this->getFolderFilterFromInput($input$context);
        $this->batchSize = $this->getBatchSizeFromInput($input);
        $this->isAsync = $input->getOption('async');
        $this->isStrict = $input->getOption('strict');
    }

    private function getBatchSizeFromInput(InputInterface $input): int
    {
        $rawInput = $input->getOption('batch-size');

        if (!is_numeric($rawInput)) {
            throw MediaException::invalidBatchSize();
        }

        return (int) $rawInput;
    }

    private function getFolderFilterFromInput(InputInterface $input, Context $context): ?EqualsAnyFilter
    {
        $rawInput = $input->getOption('folder-name');
        if (empty($rawInput)) {
            return null;
        }

        
return self::SUCCESS;
    }

    private function validateBatchSize(InputInterface $input): int
    {
        $batchSize = $input->getOption('batch-size');
        if ($batchSize === null) {
            return 100;
        }

        if (!is_numeric($batchSize)) {
            throw MediaException::invalidBatchSize();
        }

        return (int) $batchSize;
    }

    private function getMediaCount(Context $context): int
    {
        $criteria = new Criteria();
        $criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_EXACT);
        $criteria->setLimit(1);
        $result = $this->mediaRepository->search($criteria$context);

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