Skip to content

Commit 17976b5

Browse files
authored
Merge pull request #39 from bavix/dev
2.5-Dev: Bug fixes
2 parents 772c54c + bbe1fc6 commit 17976b5

File tree

9 files changed

+47
-6
lines changed

9 files changed

+47
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Add the `HasWallet` trait and `Product` interface to `Item` model.
8787
```php
8888
use Bavix\Wallet\Traits\HasWallet;
8989
use Bavix\Wallet\Interfaces\Product;
90+
use Bavix\Wallet\Interfaces\Customer;
9091

9192
class Item extends Model implements Product
9293
{

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ The operation is now executed in the transaction and updates the new `refund` fi
237237
- Exceptions: AmountInvalid, BalanceIsEmpty.
238238
- Models: Transfer, Transaction.
239239

240-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/2.4.0...HEAD
240+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/2.4.0...dev
241241
[2.4.0]: https://github.com/bavix/laravel-wallet/compare/2.3.2...2.4.0
242242
[2.3.2]: https://github.com/bavix/laravel-wallet/compare/2.3.1...2.3.2
243243
[2.3.1]: https://github.com/bavix/laravel-wallet/compare/2.3.0...2.3.1

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
]
5151
},
5252
"branch-alias": {
53-
"dev-master": "2.5-dev"
53+
"3.0.x-dev": "alpha"
5454
}
5555
},
5656
"config": {

src/Models/Wallet.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,18 @@ public function setNameAttribute(string $name): void
7474

7575
/**
7676
* @return bool
77+
* @deprecated
78+
* @see refreshBalance
7779
*/
7880
public function calculateBalance(): bool
81+
{
82+
return $this->refreshBalance();
83+
}
84+
85+
/**
86+
* @return bool
87+
*/
88+
public function refreshBalance(): bool
7989
{
8090
$balance = $this->getAvailableBalance();
8191
WalletProxy::set($this->getKey(), $balance);

src/Traits/CanPay.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Bavix\Wallet\Exceptions\ProductEnded;
66
use Bavix\Wallet\Interfaces\Product;
77
use Bavix\Wallet\Models\Transfer;
8-
use Bavix\Wallet\Models\Wallet;
98
use Illuminate\Database\Eloquent\Model;
109
use Illuminate\Database\Eloquent\ModelNotFoundException;
1110
use Illuminate\Support\Facades\DB;

src/Traits/HasWallet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ public function forceTransfer(Wallet $wallet, int $amount, ?array $meta = null,
300300
* holder transfers
301301
*
302302
* @return MorphMany
303+
* @deprecated since laravel-wallet 2.5
304+
* @see transfers
303305
*/
304306
public function holderTransfers(): MorphMany
305307
{

src/WalletServiceProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ public function boot(): void
2424
return;
2525
}
2626

27-
$this->publishes([
28-
\dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'),
29-
], 'laravel-wallet-config');
27+
$this->loadMigrationsFrom([
28+
__DIR__.'/../database/migrations_v1',
29+
__DIR__.'/../database/migrations_v2',
30+
]);
31+
32+
if (\function_exists('config_path')) {
33+
$this->publishes([
34+
\dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'),
35+
], 'laravel-wallet-config');
36+
}
3037

3138
$this->publishes([
3239
\dirname(__DIR__) . '/database/migrations_v1/' => database_path('migrations'),

tests/MultiWalletTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,25 @@ public function testGetWallet(): void
293293
);
294294
}
295295

296+
/**
297+
* @return void
298+
*/
299+
public function testGetWalletOptimize(): void
300+
{
301+
/**
302+
* @var UserMulti $user
303+
*/
304+
$user = factory(UserMulti::class)->create();
305+
$names = \range('a', 'z');
306+
foreach ($names as $name) {
307+
$user->createWallet(\compact('name'));
308+
}
309+
310+
$user->load('wallets'); // optimize
311+
312+
foreach ($names as $name) {
313+
$this->assertEquals($name, $user->getWallet($name)->name);
314+
}
315+
}
316+
296317
}

tests/WalletTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public function testRecalculate(): void
208208
$this->assertEquals($user->balance, 100);
209209

210210
$user->withdraw($user->balance);
211+
$this->assertEquals($user->balance, 0);
211212
}
212213

213214
}

0 commit comments

Comments
 (0)