44
55use Bavix \Wallet \Interfaces \Storable ;
66use Bavix \Wallet \Models \Wallet ;
7- use Bavix \Wallet \Objects \Cart ;
87use Bavix \Wallet \Services \CommonService ;
98use Bavix \Wallet \Services \ProxyService ;
109use Bavix \Wallet \Services \WalletService ;
1110use Bavix \Wallet \Test \Models \Buyer ;
1211use Bavix \Wallet \Test \Models \UserMulti ;
1312use Illuminate \Support \Facades \DB ;
13+ use PHPUnit \Framework \MockObject \MockObject ;
14+ use PDOException ;
1415use function app ;
1516
1617class BalanceTest extends TestCase
@@ -148,7 +149,7 @@ public function testFailUpdate(): void
148149 $ this ->assertTrue ($ wallet ->exists );
149150
150151 /**
151- * @var Wallet $mockWallet
152+ * @var Wallet|MockObject $mockWallet
152153 */
153154 $ mockWallet = $ this ->createMock (\get_class ($ wallet ));
154155 $ mockWallet ->method ('update ' )->willReturn (false );
@@ -161,6 +162,36 @@ public function testFailUpdate(): void
161162 $ this ->assertEquals (0 , app (Storable::class)->getBalance ($ wallet ));
162163 }
163164
165+ /**
166+ * @return void
167+ * @throws
168+ */
169+ public function testThrowUpdate (): void
170+ {
171+ $ this ->expectException (PDOException::class);
172+
173+ /**
174+ * @var Buyer $buyer
175+ */
176+ $ buyer = factory (Buyer::class)->create ();
177+ $ this ->assertFalse ($ buyer ->relationLoaded ('wallet ' ));
178+ $ wallet = $ buyer ->wallet ;
179+
180+ $ this ->assertFalse ($ wallet ->exists );
181+ $ this ->assertEquals ($ wallet ->balance , 0 );
182+ $ this ->assertTrue ($ wallet ->exists );
183+
184+ /**
185+ * @var Wallet|MockObject $mockWallet
186+ */
187+ $ mockWallet = $ this ->createMock (\get_class ($ wallet ));
188+ $ mockWallet ->method ('update ' )->willThrowException (new PDOException ());
189+ $ mockWallet ->method ('getKey ' )->willReturn ($ wallet ->getKey ());
190+
191+ app (CommonService::class)
192+ ->addBalance ($ mockWallet , 100 );
193+ }
194+
164195 /**
165196 * @throws
166197 */
0 commit comments