Skip to content

Commit 41cacd7

Browse files
HP-1631: added BuilderInterface::createSale() and BuilderInterface::buildAction() methods
1 parent 1e0f18e commit 41cacd7

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tests/behat/bootstrap/BuilderInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function buildTarget(string $name);
2828

2929
public function recreatePlan(string $name);
3030

31-
public function buildSale(string $target, string $plan, string $time, ?string $closeTime = null);
31+
public function buildSale(string $target, string $planName, string $time);
32+
33+
public function createSale(string $target, string $planName, string $time, ?string $closeTime = null);
3234

3335
public function buildPurchase(string $target, string $plan, string $time, ?array $uses = []);
3436

@@ -38,6 +40,8 @@ public function performBilling(string $time): void;
3840

3941
public function setAction(string $type, int $amount, string $unit, string $target, string $time): void;
4042

43+
public function buildAction(array $data);
44+
4145
public function performCalculation(string $time): array;
4246

4347
public function targetChangePlan(string $target, string $planName, string $date, string $wallTime = null);

tests/behat/bootstrap/FactoryBasedBuilder.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use hiqdev\php\billing\price\PriceFactory;
1919
use hiqdev\php\billing\price\RatePrice;
2020
use hiqdev\php\billing\price\SinglePrice;
21+
use hiqdev\php\billing\sale\SaleInterface;
2122
use hiqdev\php\billing\target\Target;
2223
use hiqdev\php\billing\tests\support\order\SimpleBilling;
2324
use hiqdev\php\billing\tests\support\tools\SimpleFactory;
@@ -33,11 +34,12 @@ class FactoryBasedBuilder implements BuilderInterface
3334

3435
private $plan;
3536

36-
private $sale;
37+
private SaleInterface $sale;
3738

3839
private $prices = [];
3940

40-
private $actions = [];
41+
/** @var ActionInterface[] */
42+
private array $actions = [];
4143

4244
private $factory;
4345

@@ -122,13 +124,18 @@ public function recreatePlan(string $name)
122124
$plan->setPrices($this->prices);
123125
}
124126

125-
public function buildSale(string $target, $plan, string $time = null, ?string $closeTime = null)
127+
public function buildSale(string $target, $planName, string $time = null, ?string $closeTime = null)
128+
{
129+
return $this->createSale($target, $planName, $time, $closeTime);
130+
}
131+
132+
public function createSale(string $target, $planName, string $time = null, ?string $closeTime = null)
126133
{
127134
$this->time = $time;
128135
$this->sale = $this->factory->getSale(array_filter([
129136
'customer' => $this->customer,
130137
'target' => $target,
131-
'plan' => $plan,
138+
'plan' => $planName,
132139
'time' => $time,
133140
'closeTime' => $closeTime,
134141
]));
@@ -198,10 +205,10 @@ public function buildAction(array $data): ActionInterface
198205
$data['time'] = $data['time'] ?? $this->time;
199206
$data['customer'] = $data['customer'] ?? $this->customer;
200207
if (!empty($data['targets'])) {
201-
$data['target'] = $this->factory->get('targets', $data['targets']);
208+
$data['target'] = $this->factory->getTargets($data['targets']);
202209
}
203210

204-
return $this->factory->get('action', $data);
211+
return $this->factory->getAction($data);
205212
}
206213

207214
public function findBills(array $data): array

0 commit comments

Comments
 (0)