weight = $baseWeightGrams; $order->setRelation('shopping_order_items', new Collection($items)); return $order; } function dhlWeightItem(int $comp, int $qty, int $productWeightGrams): ShoppingOrderItem { $product = new Product; $product->weight = $productWeightGrams; $item = new ShoppingOrderItem; $item->comp = $comp; $item->qty = $qty; $item->setRelation('product', $product); return $item; } it('uses the shopping order weight as DHL base weight', function () { $weight = (new DhlShipmentWeightCalculator)->calculate(dhlWeightOrder(1250)); expect($weight)->toBe(1.25); }); it('adds compensation product weights to the DHL weight', function () { $weight = (new DhlShipmentWeightCalculator)->calculate(dhlWeightOrder(500, [ dhlWeightItem(comp: 1, qty: 2, productWeightGrams: 250), dhlWeightItem(comp: 0, qty: 10, productWeightGrams: 1000), ])); expect($weight)->toBe(1.0); }); it('falls back to a safe default DHL weight when no weight exists', function () { $weight = (new DhlShipmentWeightCalculator)->calculate(dhlWeightOrder(0)); expect($weight)->toBe(1.0); }); it('validates product specific DHL weight limits', function () { (new DhlShipmentWeightCalculator)->assertWithinProductLimit(1.001, 'V62KP'); })->throws(InvalidArgumentException::class, 'Gewicht 1.001 kg ueberschreitet das DHL-Maximalgewicht fuer V62KP (1.0 kg).'); it('allows regular parcel products up to the DHL parcel limit', function () { (new DhlShipmentWeightCalculator)->assertWithinProductLimit(31.5, 'V01PAK'); expect(true)->toBeTrue(); });