Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCase.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | ||||
use Illuminate\Routing\Middleware\ThrottleRequests; | |||||
abstract class TestCase extends BaseTestCase | abstract class TestCase extends BaseTestCase | ||||
{ | { | ||||
use TestCaseTrait; | use TestCaseTrait; | ||||
use TestCaseMeetTrait; | use TestCaseMeetTrait; | ||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
// Disable throttling | |||||
$this->withoutMiddleware(ThrottleRequests::class); | |||||
} | |||||
protected function backdateEntitlements($entitlements, $targetDate) | protected function backdateEntitlements($entitlements, $targetDate) | ||||
{ | { | ||||
$wallets = []; | |||||
$ids = []; | |||||
foreach ($entitlements as $entitlement) { | foreach ($entitlements as $entitlement) { | ||||
$entitlement->created_at = $targetDate; | $ids[] = $entitlement->id; | ||||
$entitlement->updated_at = $targetDate; | $wallets[] = $entitlement->wallet_id; | ||||
$entitlement->save(); | } | ||||
$owner = $entitlement->wallet->owner; | \App\Entitlement::whereIn('id', $ids)->update([ | ||||
$owner->created_at = $targetDate; | 'created_at' => $targetDate, | ||||
$owner->save(); | 'updated_at' => $targetDate, | ||||
]); | |||||
if (!empty($wallets)) { | |||||
$wallets = array_unique($wallets); | |||||
$owners = \App\Wallet::whereIn('id', $wallets)->pluck('user_id')->all(); | |||||
\App\User::whereIn('id', $owners)->update(['created_at' => $targetDate]); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Set baseURL to the admin UI location | * Set baseURL to the admin UI location | ||||
*/ | */ | ||||
protected static function useAdminUrl(): void | protected static function useAdminUrl(): void | ||||
{ | { | ||||
// This will set base URL for all tests in a file. | // This will set base URL for all tests in a file. | ||||
// If we wanted to access both user and admin in one test | // If we wanted to access both user and admin in one test | ||||
// we can also just call post/get/whatever with full url | // we can also just call post/get/whatever with full url | ||||
\config(['app.url' => str_replace('//', '//admin.', \config('app.url'))]); | \config(['app.url' => str_replace('//', '//admin.', \config('app.url'))]); | ||||
url()->forceRootUrl(config('app.url')); | url()->forceRootUrl(config('app.url')); | ||||
} | } | ||||
/** | |||||
* Set baseURL to the reseller UI location | |||||
*/ | |||||
protected static function useResellerUrl(): void | |||||
{ | |||||
// This will set base URL for all tests in a file. | |||||
// If we wanted to access both user and admin in one test | |||||
// we can also just call post/get/whatever with full url | |||||
\config(['app.url' => str_replace('//', '//reseller.', \config('app.url'))]); | |||||
url()->forceRootUrl(config('app.url')); | |||||
} | |||||
} | } |