Skip to content

Commit 2f5715a

Browse files
authored
AHN-2700: find charge by type, object and quantity (#108)
* AHN-2700: add possibility to find multiple charges for one object * csfix
1 parent e28267a commit 2f5715a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/behat/bootstrap/BillingContext.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function chargeWithTarget($type, $amount, $currency, $quantity, $unit, $t
376376
{
377377
$quantity = $this->prepareQuantity($quantity);
378378
$amount = $this->prepareSum($amount, $quantity);
379-
$charge = $this->findCharge($type, $target);
379+
$charge = $this->findCharge($type, $target, $quantity);
380380
Assert::assertNotNull($charge);
381381
Assert::assertSame($type, $charge->getType()->getName());
382382
Assert::assertSame($target, $charge->getTarget()->getFullName());
@@ -386,7 +386,23 @@ public function chargeWithTarget($type, $amount, $currency, $quantity, $unit, $t
386386
Assert::assertEquals(strtolower($unit), strtolower($charge->getUsage()->getUnit()->getName()));
387387
}
388388

389-
public function findCharge($type, $target): ?ChargeInterface
389+
public function findCharge($type, $target, $quantity = null): ?ChargeInterface
390+
{
391+
$charges = $this->findCharges($type, $target);
392+
if ($charges === null) {
393+
return null;
394+
}
395+
396+
foreach ($charges as $charge) {
397+
if ((string) $quantity === (string) $charge->getUsage()->getQuantity()) {
398+
return $charge;
399+
}
400+
}
401+
402+
return $charge;
403+
}
404+
405+
public function findCharges($type, $target): ?array
390406
{
391407
foreach ($this->charges as $charge) {
392408
if ($charge->getType()->getName() !== $type) {
@@ -396,10 +412,10 @@ public function findCharge($type, $target): ?ChargeInterface
396412
continue;
397413
}
398414

399-
return $charge;
415+
$charges[] = $charge;
400416
}
401417

402-
return null;
418+
return $charges ?? null;
403419
}
404420

405421
public function getNextCharge(): ChargeInterface

0 commit comments

Comments
 (0)