77use  function  app ;
88use  Bavix \Wallet \Models \Wallet ;
99use  Bavix \Wallet \Services \BookkeeperServiceInterface ;
10- use  Bavix \Wallet \Services \CommonServiceLegacy ;
1110use  Bavix \Wallet \Services \RegulatorServiceInterface ;
11+ use  Bavix \Wallet \Services \StateServiceInterface ;
1212use  Bavix \Wallet \Test \Infra \Factories \BuyerFactory ;
1313use  Bavix \Wallet \Test \Infra \Models \Buyer ;
1414use  Bavix \Wallet \Test \Infra \TestCase ;
@@ -77,7 +77,7 @@ public function testWithdrawWalletExists(): void
7777    /** 
7878     * @throws 
7979     */ 
80-     public  function  testSimple (): void 
80+     public  function  testSimpleLLLL (): void 
8181    {
8282        /** @var Buyer $buyer */ 
8383        $ buyer  = BuyerFactory::new ()->create ();
@@ -92,8 +92,10 @@ public function testSimple(): void
9292        $ wallet ->deposit (1000 );
9393        self ::assertSame (1000 , $ wallet ->balanceInt );
9494
95-         $ result  = app (CommonServiceLegacy::class)->addBalance ($ wallet , 100 );
96-         self ::assertTrue ($ result );
95+         $ result  = app (RegulatorServiceInterface::class)->increase ($ wallet , 100 );
96+         app (StateServiceInterface::class)->persist ($ wallet );
97+ 
98+         self ::assertSame (1100 , (int ) $ result );
9799
98100        self ::assertSame (1100 , $ wallet ->balanceInt );
99101        self ::assertTrue ($ wallet ->refreshBalance ());
@@ -104,8 +106,10 @@ public function testSimple(): void
104106        self ::assertTrue ($ wallet ->delete ());
105107        self ::assertFalse ($ wallet ->exists );
106108        self ::assertSame ($ wallet ->getKey (), $ key );
107-         $ result  = app (CommonServiceLegacy::class)->addBalance ($ wallet , 100 );
108-         self ::assertTrue ($ result ); // automatic create default wallet 
109+         $ result  = app (RegulatorServiceInterface::class)->increase ($ wallet , 100 );
110+         app (StateServiceInterface::class)->persist ($ wallet );
111+ 
112+         self ::assertSame (1100 , (int ) $ result ); // automatic create default wallet 
109113
110114        $ wallet ->refreshBalance ();
111115        $ balance  = 0 ;
@@ -226,40 +230,4 @@ public function testForceUpdate(): void
226230        self ::assertSame (1000 , $ wallet ->balanceInt );
227231        self ::assertSame (1000 , (int ) $ wallet ->getRawOriginal ('balance ' ));
228232    }
229- 
230-     public  function  testFailUpdate (): void 
231-     {
232-         /** @var Buyer $buyer */ 
233-         $ buyer  = BuyerFactory::new ()->create ();
234-         self ::assertFalse ($ buyer ->relationLoaded ('wallet ' ));
235-         $ wallet  = $ buyer ->wallet ;
236- 
237-         self ::assertFalse ($ wallet ->exists );
238-         self ::assertSame (0 , $ wallet ->balanceInt );
239-         self ::assertTrue ($ wallet ->exists );
240- 
241-         /** @var MockObject|Wallet $mockQuery */ 
242-         $ mockQuery  = $ this  ->createMock (\get_class ($ wallet ->newQuery ()));
243-         $ mockQuery ->method ('whereKey ' )->willReturn ($ mockQuery );
244-         $ mockQuery ->method ('update ' )->willReturn (0 );
245- 
246-         /** @var MockObject|Wallet $mockWallet */ 
247-         $ mockWallet  = $ this  ->createMock (\get_class ($ wallet ));
248-         $ mockWallet ->method ('newQuery ' )->willReturn ($ mockQuery );
249-         $ mockWallet ->method ('getKey ' )->willReturn ($ wallet ->getKey ());
250-         $ mockWallet ->method ('fill ' )->willReturn ($ mockWallet );
251-         $ mockWallet ->method ('syncOriginalAttribute ' )->willReturn ($ mockWallet );
252-         $ mockWallet ->method ('__get ' )->with ('uuid ' )->willReturn ($ wallet ->uuid );
253- 
254-         $ bookkeeper  = app (BookkeeperServiceInterface::class);
255-         $ regulator  = app (RegulatorServiceInterface::class);
256-         $ result  = app (CommonServiceLegacy::class)
257-             ->addBalance ($ mockWallet , 100 )
258-         ;
259- 
260-         self ::assertFalse ($ result );
261-         self ::assertSame ('0 ' , $ regulator ->amount ($ wallet ));
262-         self ::assertSame ('0 ' , $ bookkeeper ->amount ($ wallet ));
263-         self ::assertSame ('0 ' , $ wallet ->balance );
264-     }
265233}
0 commit comments