|
5 | 5 | use Bavix\Wallet\Interfaces\Storable; |
6 | 6 | use Bavix\Wallet\Models\Wallet; |
7 | 7 | use Bavix\Wallet\Services\CommonService; |
8 | | -use Bavix\Wallet\Services\ProxyService; |
9 | | -use Bavix\Wallet\Services\WalletService; |
| 8 | +use Bavix\Wallet\Simple\Store; |
10 | 9 | use Bavix\Wallet\Test\Models\Buyer; |
11 | 10 | use Bavix\Wallet\Test\Models\UserMulti; |
12 | 11 | use Illuminate\Support\Facades\DB; |
@@ -224,7 +223,6 @@ public function testArtisanRefresh(): void |
224 | 223 | } |
225 | 224 |
|
226 | 225 | // fresh balance |
227 | | - app(ProxyService::class)->fresh(); |
228 | 226 | DB::table(config('wallet.wallet.table')) |
229 | 227 | ->update(['balance' => 0]); |
230 | 228 |
|
@@ -254,13 +252,30 @@ public function testForceUpdate(): void |
254 | 252 | Wallet::whereKey($buyer->wallet->getKey()) |
255 | 253 | ->update(['balance' => 10]); |
256 | 254 |
|
257 | | - app(ProxyService::class)->fresh(); |
| 255 | + /** |
| 256 | + * Create a state when the cache is empty. |
| 257 | + * For example, something went wrong and your database has incorrect data. |
| 258 | + * Unfortunately, the library will work with what is. |
| 259 | + * But there is an opportunity to recount the balance. |
| 260 | + * |
| 261 | + * Here is an example: |
| 262 | + */ |
| 263 | + app()->singleton(Storable::class, Store::class); |
| 264 | + $this->assertEquals($wallet->getRawOriginal('balance'), 1000); |
258 | 265 |
|
| 266 | + /** |
| 267 | + * We load the model from the base and our balance is 10. |
| 268 | + */ |
259 | 269 | $wallet->refresh(); |
260 | 270 | $this->assertEquals($wallet->balance, 10); |
| 271 | + $this->assertEquals($wallet->getRawOriginal('balance'), 10); |
261 | 272 |
|
| 273 | + /** |
| 274 | + * Now we fill the cache with relevant data (PS, the data inside the model will be updated). |
| 275 | + */ |
262 | 276 | $wallet->refreshBalance(); |
263 | 277 | $this->assertEquals($wallet->balance, 1000); |
| 278 | + $this->assertEquals($wallet->getRawOriginal('balance'), 1000); |
264 | 279 | } |
265 | 280 |
|
266 | 281 | } |
0 commit comments