Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCaseTrait.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Transaction; | |||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | |||||
use Illuminate\Contracts\Console\Kernel; | use Illuminate\Contracts\Console\Kernel; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use PHPUnit\Framework\Assert; | use PHPUnit\Framework\Assert; | ||||
trait TestCaseTrait | trait TestCaseTrait | ||||
{ | { | ||||
protected function assertUserEntitlements($user, $expected) | protected function assertUserEntitlements($user, $expected) | ||||
{ | { | ||||
Show All 18 Lines | trait TestCaseTrait | ||||
{ | { | ||||
$app = require __DIR__ . '/../bootstrap/app.php'; | $app = require __DIR__ . '/../bootstrap/app.php'; | ||||
$app->make(Kernel::class)->bootstrap(); | $app->make(Kernel::class)->bootstrap(); | ||||
return $app; | return $app; | ||||
} | } | ||||
/** | |||||
* Create a set of transaction log entries for a wallet | |||||
*/ | |||||
protected function createTestTransactions($wallet) | |||||
{ | |||||
$result = []; | |||||
$date = Carbon::now(); | |||||
$debit = 0; | |||||
$entitlementTransactions = []; | |||||
foreach ($wallet->entitlements as $entitlement) { | |||||
if ($entitlement->cost) { | |||||
$debit += $entitlement->cost; | |||||
$entitlementTransactions[] = $entitlement->createTransaction( | |||||
Transaction::ENTITLEMENT_BILLED, | |||||
$entitlement->cost | |||||
); | |||||
} | |||||
} | |||||
$transaction = Transaction::create([ | |||||
'user_email' => null, | |||||
'object_id' => $wallet->id, | |||||
'object_type' => \App\Wallet::class, | |||||
'type' => Transaction::WALLET_DEBIT, | |||||
'amount' => $debit, | |||||
'description' => 'Payment', | |||||
]); | |||||
$result[] = $transaction; | |||||
Transaction::whereIn('id', $entitlementTransactions)->update(['transaction_id' => $transaction->id]); | |||||
$transaction = Transaction::create([ | |||||
'user_email' => null, | |||||
'object_id' => $wallet->id, | |||||
'object_type' => \App\Wallet::class, | |||||
'type' => Transaction::WALLET_CREDIT, | |||||
'amount' => 2000, | |||||
'description' => 'Payment', | |||||
]); | |||||
$transaction->created_at = $date->next(Carbon::MONDAY); | |||||
$transaction->save(); | |||||
$result[] = $transaction; | |||||
$types = [ | |||||
Transaction::WALLET_AWARD, | |||||
Transaction::WALLET_PENALTY, | |||||
]; | |||||
// The page size is 10, so we generate so many to have at least two pages | |||||
$loops = 10; | |||||
while ($loops-- > 0) { | |||||
$transaction = Transaction::create([ | |||||
'user_email' => 'jeroen.@jeroen.jeroen', | |||||
'object_id' => $wallet->id, | |||||
'object_type' => \App\Wallet::class, | |||||
'type' => $types[count($result) % count($types)], | |||||
'amount' => 11 * (count($result) + 1), | |||||
'description' => 'TRANS' . $loops, | |||||
]); | |||||
$transaction->created_at = $date->next(Carbon::MONDAY); | |||||
$transaction->save(); | |||||
$result[] = $transaction; | |||||
} | |||||
return $result; | |||||
} | |||||
protected function deleteTestDomain($name) | protected function deleteTestDomain($name) | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$domain = Domain::withTrashed()->where('namespace', $name)->first(); | $domain = Domain::withTrashed()->where('namespace', $name)->first(); | ||||
if (!$domain) { | if (!$domain) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |