99, 2 => 99, 3 => 99]); $this->assertSame([1 => 50, 2 => 50, 3 => 50], $discounts); $this->assertSame(150, array_sum($discounts), 'Auf der Warenkorbsumme gerundet wären es 149 Cent.'); } public function test_a_percentage_never_exceeds_the_line_price(): void { $this->assertSame([1 => 4900], DiscountCalculator::allocate(DiscountCode::PERCENT, 100, null, [1 => 4900])); $this->assertSame([1 => 4900], DiscountCalculator::allocate(DiscountCode::PERCENT, 250, null, [1 => 4900])); $this->assertSame([1 => 0], DiscountCalculator::allocate(DiscountCode::PERCENT, 0, null, [1 => 4900])); } public function test_a_fixed_amount_is_distributed_in_proportion_to_the_prices(): void { $this->assertSame([1 => 600, 2 => 400], DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 1000, [1 => 3000, 2 => 2000])); } public function test_the_remaining_cents_go_to_the_largest_remainder_and_the_sum_is_exact(): void { $discounts = DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 100, [1 => 3333, 2 => 3333, 3 => 3334]); $this->assertSame([1 => 33, 2 => 33, 3 => 34], $discounts); $this->assertSame(100, array_sum($discounts)); } public function test_a_fixed_amount_is_capped_at_the_affected_total(): void { $discounts = DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 99999, [1 => 2900, 2 => 4900]); $this->assertSame([1 => 2900, 2 => 4900], $discounts); } public function test_nothing_to_discount_yields_nothing(): void { $this->assertSame([], DiscountCalculator::allocate(DiscountCode::PERCENT, 10, null, [])); $this->assertSame([1 => 0], DiscountCalculator::allocate(DiscountCode::AMOUNT, null, 0, [1 => 100])); } public function test_codes_are_normalised_without_spaces_and_in_capitals(): void { $this->assertSame('ZERT-2026', DiscountCode::normalise(' zert-2026 ')); $this->assertSame('SOMMER10', DiscountCode::normalise('sommer 10')); } }