Skip to content

Commit c38e441

Browse files
committed
test: make product adjustable
1 parent 0c61b23 commit c38e441

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/Utils/Product.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88
namespace Vaened\SwiftCart\Tests\Utils;
99

1010
use Vaened\PriceEngine\Adjustments\Adjusters;
11+
use Vaened\PriceEngine\Adjustments\Charge;
12+
use Vaened\PriceEngine\Adjustments\Discount;
1113
use Vaened\PriceEngine\Money\Amount;
1214
use Vaened\SwiftCart\Entities\Chargeable;
1315
use Vaened\SwiftCart\Entities\Discountable;
1416
use Vaened\SwiftCart\Entities\Tradable;
1517
use Vaened\SwiftCart\UniqueId;
1618

19+
use function Lambdish\Phunctional\each;
20+
1721
final class Product implements Tradable, Discountable, Chargeable
1822
{
23+
private readonly Adjusters $charges;
24+
25+
private readonly Adjusters $discounts;
26+
1927
public function __construct(
2028
private readonly string $id,
2129
private readonly Amount $amount,
2230
)
2331
{
32+
$this->charges = Adjusters::empty();
33+
$this->discounts = Adjusters::empty();
2434
}
2535

2636
public static function random(): self
@@ -33,6 +43,19 @@ public static function create(Amount $amount): self
3343
return new self(UniqueId::random()->uniqueId(), $amount);
3444
}
3545

46+
public function with(Discount|Charge ...$adjusters): self
47+
{
48+
each(function (Discount|Charge $adjuster) {
49+
if ($adjuster instanceof Discount) {
50+
$this->discounts->push($adjuster);
51+
} else {
52+
$this->charges->push($adjuster);
53+
}
54+
}, $adjusters);
55+
56+
return $this;
57+
}
58+
3659
public function uniqueId(): string
3760
{
3861
return $this->id;
@@ -45,11 +68,11 @@ public function amount(): Amount
4568

4669
public function charges(): Adjusters
4770
{
48-
return Adjusters::empty();
71+
return $this->charges;
4972
}
5073

5174
public function discounts(): Adjusters
5275
{
53-
return Adjusters::empty();
76+
return $this->discounts;
5477
}
5578
}

0 commit comments

Comments
 (0)