Skip to content

Commit

Permalink
Laravel v6
Browse files Browse the repository at this point in the history
  • Loading branch information
MannikJ committed Apr 6, 2020
1 parent bbda34e commit 4a68f51
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
}
],
"require": {
"php": "^7.0",
"doctrine/dbal": "^2.9",
"laravel/framework": "~5.6",
"predis/predis": "^1.1"
"php": "^7.2",
"laravel/framework": "^6.0"
},
"require-dev": {
"doctrine/dbal": "^2.9",
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "^7.3"
"orchestra/testbench": "^4.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 0 additions & 3 deletions src/Jobs/RecalculateWalletBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use MannikJ\Laravel\Wallet\Models\Wallet;
use Cache;
use Illuminate\Support\Facades\Redis;
use Illuminate\Queue\Jobs\Job;

class RecalculateWalletBalance implements ShouldQueue
{
Expand Down
7 changes: 4 additions & 3 deletions src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Arr;

class Transaction extends Model
{
Expand Down Expand Up @@ -101,7 +102,7 @@ public function setAmountAttribute($amount)

public function getAmountWithSign($amount = null, $type = null)
{
$amount = $amount ?: array_get($this->attributes, 'amount');
$amount = $amount ?: Arr::get($this->attributes, 'amount');
$type = $type ?: $this->type;
$amount = $this->shouldConvertToAbsoluteAmount() ? abs($amount) : $amount;
if (in_array($type, config('wallet.subtracting_transaction_types', []))) {
Expand All @@ -121,7 +122,7 @@ public function getTotalAmount()
{
// $totalAmount = $this->amount + $this->children()->get()->sum('amount');
$totalAmount = $this->where('id', $this->id)->selectTotalAmount()->first();
$totalAmount = $totalAmount ? array_get($totalAmount->getAttributes(), 'total_amount') : null;
$totalAmount = $totalAmount ? Arr::get($totalAmount->getAttributes(), 'total_amount') : null;
$this->attributes['total_amount'] = $totalAmount;
return $totalAmount;
}
Expand Down Expand Up @@ -188,7 +189,7 @@ public function scopeSelectTotalAmount($query)

public function getTotalAmountAttribute()
{
$totalAmount = array_get($this->attributes, 'total_amount', $this->getTotalAmount());
$totalAmount = Arr::get($this->attributes, 'total_amount', $this->getTotalAmount());
return $totalAmount;
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestCase extends BaseTestCase
/**
* Setup the test environment.
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->withFactories(__DIR__ . '/factories');
Expand Down
2 changes: 1 addition & 1 deletion tests/factories/TransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

$factory->define(config('wallet.transaction_model'), function (Faker $faker, $attributes) {
$walletModel = config('wallet.wallet_model');
$wallet = array_has($attributes, 'wallet_id')
$wallet = Arr::has($attributes, 'wallet_id')
? $walletModel::findOrFail($attributes['wallet_id'])
: ($walletModel::first() ? : factory($walletModel)->create());
$type = $faker->randomElement([
Expand Down
3 changes: 2 additions & 1 deletion tests/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Str;
use Faker\Generator as Faker;
use MannikJ\Laravel\Wallet\Tests\Models\User;

Expand All @@ -8,6 +9,6 @@
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => bcrypt('test'),
'remember_token' => str_random(10),
'remember_token' => Str::random(10),
];
});
3 changes: 2 additions & 1 deletion tests/factories/WalletFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use Faker\Generator as Faker;
use Illuminate\Support\Arr;
use MannikJ\Laravel\Wallet\Models\Wallet;
use MannikJ\Laravel\Wallet\Tests\Models\User;

$factory->define(Wallet::class, function (Faker $faker, $attributes) {
$owner = array_has($attributes, 'owner_id')
$owner = Arr::has($attributes, 'owner_id')
? User::findOrFail($attributes['owner_id'])
: (User::first() ? : factory(User::class)->create());
return [
Expand Down

0 comments on commit 4a68f51

Please sign in to comment.