22
33namespace  Bavix \Wallet \Test ;
44
5+ use  Bavix \Wallet \Models \Transaction ;
56use  Bavix \Wallet \Test \Models \Buyer ;
67use  Bavix \Wallet \Test \Models \Item ;
78
@@ -13,6 +14,10 @@ class ProductTest extends TestCase
1314     */ 
1415    public  function  testPay (): void 
1516    {
17+         /** 
18+          * @var Buyer $buyer 
19+          * @var Item $product 
20+          */ 
1621        $ buyer  = factory (Buyer::class)->create ();
1722        $ product  = factory (Item::class)->create ([
1823            'quantity '  => 1 ,
@@ -22,7 +27,30 @@ public function testPay(): void
2227        $ buyer ->deposit ($ product ->price );
2328
2429        $ this  ->assertEquals ($ buyer ->balance , $ product ->price );
25-         $ this  ->assertNotNull ($ buyer ->pay ($ product ));
30+         $ transfer  = $ buyer ->pay ($ product );
31+         $ this  ->assertNotNull ($ transfer );
32+ 
33+         /** 
34+          * @var Transaction $withdraw 
35+          * @var Transaction $deposit 
36+          */ 
37+         $ withdraw  = $ transfer ->withdraw ;
38+         $ deposit  = $ transfer ->deposit ;
39+ 
40+         $ this  ->assertInstanceOf (Transaction::class, $ withdraw );
41+         $ this  ->assertInstanceOf (Transaction::class, $ deposit );
42+ 
43+         $ this  ->assertInstanceOf (Buyer::class, $ withdraw ->payable );
44+         $ this  ->assertInstanceOf (Item::class, $ deposit ->payable );
45+ 
46+         $ this  ->assertEquals ($ buyer ->getKey (), $ withdraw ->payable ->getKey ());
47+         $ this  ->assertEquals ($ product ->getKey (), $ deposit ->payable ->getKey ());
48+ 
49+         $ this  ->assertInstanceOf (Buyer::class, $ transfer ->from );
50+         $ this  ->assertInstanceOf (Item::class, $ transfer ->to );
51+ 
52+         $ this  ->assertEquals ($ buyer ->getKey (), $ transfer ->from ->getKey ());
53+         $ this  ->assertEquals ($ product ->getKey (), $ transfer ->to ->getKey ());
2654
2755        $ this  ->assertEquals ($ buyer ->balance , 0 );
2856        $ this  ->assertNull ($ buyer ->safePay ($ product ));
@@ -33,6 +61,10 @@ public function testPay(): void
3361     */ 
3462    public  function  testRefund (): void 
3563    {
64+         /** 
65+          * @var Buyer $buyer 
66+          * @var Item $product 
67+          */ 
3668        $ buyer  = factory (Buyer::class)->create ();
3769        $ product  = factory (Item::class)->create ([
3870            'quantity '  => 1 ,
@@ -115,4 +147,27 @@ public function testOutOfStock(): void
115147        $ buyer ->pay ($ product );
116148    }
117149
150+     /** 
151+      * @return void 
152+      */ 
153+     public  function  testForcePay (): void 
154+     {
155+         /** 
156+          * @var Buyer $buyer 
157+          * @var Item $product 
158+          */ 
159+         $ buyer  = factory (Buyer::class)->create ();
160+         $ product  = factory (Item::class)->create ([
161+             'quantity '  => 1 ,
162+         ]);
163+ 
164+         $ this  ->assertEquals ($ buyer ->balance , 0 );
165+         $ buyer ->forcePay ($ product );
166+ 
167+         $ this  ->assertEquals ($ buyer ->balance , -$ product ->price );
168+ 
169+         $ buyer ->deposit (-$ buyer ->balance );
170+         $ this  ->assertEquals ($ buyer ->balance , 0 );
171+     }
172+ 
118173}
0 commit comments