shippingCostsParameterIsMissing example


        $this->validateShippingCostsParameters($request);

        $shippingCosts = $request->get('shippingCosts');

        return new CalculatedPrice($shippingCosts['unitPrice']$shippingCosts['totalPrice']new CalculatedTaxCollection()new TaxRuleCollection());
    }

    private function validateShippingCostsParameters(Request $request): void
    {
        if (!$request->request->has('shippingCosts')) {
            throw ApiException::shippingCostsParameterIsMissing();
        }

        $validation = new DataValidationDefinition('shipping-cost');
        $validation->add('unitPrice', new NotBlank()new Type('numeric')new GreaterThanOrEqual(['value' => 0]));
        $validation->add('totalPrice', new NotBlank()new Type('numeric')new GreaterThanOrEqual(['value' => 0]));
        $this->validator->validate($request->request->all('shippingCosts')$validation);
    }
}
public function testCustomerIdParameterIsMissing(): void
    {
        $exception = ApiException::customerIdParameterIsMissing();

        static::assertEquals(ApiException::API_CUSTOMER_ID_PARAMETER_IS_MISSING, $exception->getErrorCode());
        static::assertEquals('Parameter "customerId" is missing.', $exception->getMessage());
    }

    public function testShippingCostsParameterIsMissing(): void
    {
        $exception = ApiException::shippingCostsParameterIsMissing();

        static::assertEquals(ApiException::API_SHIPPING_COSTS_PARAMETER_IS_MISSING, $exception->getErrorCode());
        static::assertEquals('Parameter "shippingCosts" is missing.', $exception->getMessage());
    }

    public function testUnableGenerateBundle(): void
    {
        $exception = ApiException::unableGenerateBundle('bundleName');

        static::assertEquals(ApiException::API_UNABLE_GENERATE_BUNDLE, $exception->getErrorCode());
        static::assertEquals('Unable to generate bundle directory for bundle "bundleName".', $exception->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.