File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public function getBalance(Wallet $object): int
6767        $ wallet ->exists  or  $ wallet ->save ();
6868        $ proxy  = app (ProxyService::class);
6969        if  (!$ proxy ->has ($ wallet ->getKey ())) {
70-             $ proxy ->set ($ wallet ->getKey (), (int )( $ wallet ->attributes [ 'balance ' ] ??  0 ));
70+             $ proxy ->set ($ wallet ->getKey (), (int )$ wallet ->getOriginal ( 'balance ' ,  0 ));
7171        }
7272
7373        return  $ proxy [$ wallet ->getKey ()];
Original file line number Diff line number Diff line change 33namespace  Bavix \Wallet \Test ;
44
55use  Bavix \Wallet \Services \CommonService ;
6+ use  Bavix \Wallet \Services \ProxyService ;
67use  Bavix \Wallet \Test \Models \Buyer ;
78use  function  app ;
9+ use  Illuminate \Support \Facades \DB ;
810
911class  BalanceTest extends  TestCase
1012{
@@ -45,4 +47,30 @@ public function testSimple(): void
4547        $ this  ->assertEquals ($ wallet ->balance , 1001 );
4648    }
4749
50+     /** 
51+      * @return void 
52+      * @see https://github.com/bavix/laravel-wallet/issues/49 
53+      */ 
54+     public  function  testForceUpdate (): void 
55+     {
56+         /** 
57+          * @var Buyer $buyer 
58+          */ 
59+         $ buyer  = factory (Buyer::class)->create ();
60+         $ wallet  = $ buyer ->wallet ;
61+ 
62+         $ this  ->assertEquals ($ wallet ->balance , 0 );
63+ 
64+         $ wallet ->deposit (1000 );
65+         $ this  ->assertEquals ($ wallet ->balance , 1000 );
66+ 
67+         $ buyer ->wallet ->update (['balance '  => 10 ]);
68+         app (ProxyService::class)->fresh ();
69+ 
70+         $ this  ->assertEquals ($ wallet ->balance , 10 );
71+         $ wallet ->refreshBalance ();
72+         
73+         $ this  ->assertEquals ($ wallet ->balance , 1000 );
74+     }
75+ 
4876}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments