Skip to content

Commit 7ab3eab

Browse files
committed
update unit's
1 parent 39aa9b5 commit 7ab3eab

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Traits/CanBePaid.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ public function refundGift(Product $product, bool $force = false): bool
171171
return $this->refund($product, $force, true);
172172
}
173173

174+
/**
175+
* @param Product $product
176+
* @param bool $force
177+
* @return bool
178+
*/
179+
public function safeRefundGift(Product $product, bool $force = false): bool
180+
{
181+
try {
182+
return $this->refundGift($product, $force);
183+
} catch (\Throwable $throwable) {
184+
return false;
185+
}
186+
}
187+
174188
/**
175189
* @param Product $product
176190
* @return bool

tests/GiftTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ public function testRefund(): void
6363

6464
$this->assertFalse($second->wallet->safeRefund($product));
6565
$this->assertTrue($second->wallet->refundGift($product));
66+
67+
$this->assertEquals($first->balance, $product->getAmountProduct());
68+
$this->assertEquals($second->balance, 0);
69+
70+
$this->assertNull($second->wallet->safeGift($first, $product));
71+
$this->assertNotNull($second->wallet->forceGift($first, $product));
72+
73+
$this->assertEquals($second->balance, -$product->getAmountProduct());
74+
75+
$second->deposit(-$second->balance);
76+
$this->assertEquals($second->balance, 0);
77+
78+
$first->withdraw($product->getAmountProduct());
79+
$this->assertEquals($first->balance, 0);
80+
81+
$product->withdraw($product->balance);
82+
$this->assertEquals($product->balance, 0);
83+
84+
$this->assertFalse($first->safeRefundGift($product));
85+
$this->assertTrue($first->forceRefundGift($product));
86+
$this->assertEquals($product->balance, -$product->getAmountProduct());
87+
88+
$first->withdraw($first->balance);
89+
$this->assertEquals($first->balance, 0);
6690
}
6791

6892
}

0 commit comments

Comments
 (0)