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\Transaction; | ||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | 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 | ||||
{ | { | ||||
/** | |||||
* Assign beta entitlement to a user. | |||||
* It will add both requested entitlement as well as the 'beta' entitlement | |||||
* | |||||
* @param string|\App\User $user The user | |||||
* @param string $sku The beta SKU title | |||||
*/ | |||||
protected function assignBetaEntitlement($user, $sku): void | |||||
{ | |||||
if (is_string($user)) { | |||||
$user = $this->getTestUser($user); | |||||
} | |||||
$user->assignSku(\App\Sku::where('title', 'beta')->first()); | |||||
$user->assignSku(\App\Sku::where('title', $sku)->first()); | |||||
} | |||||
protected function assertUserEntitlements($user, $expected) | protected function assertUserEntitlements($user, $expected) | ||||
{ | { | ||||
// Assert the user entitlements | // Assert the user entitlements | ||||
$skus = $user->entitlements()->get() | $skus = $user->entitlements()->get() | ||||
->map(function ($ent) { | ->map(function ($ent) { | ||||
return $ent->sku->title; | return $ent->sku->title; | ||||
}) | }) | ||||
->toArray(); | ->toArray(); | ||||
sort($skus); | sort($skus); | ||||
Assert::assertSame($expected, $skus); | Assert::assertSame($expected, $skus); | ||||
} | } | ||||
/** | /** | ||||
* Removes all beta entitlements from the database | |||||
*/ | |||||
protected function clearBetaEntitlements(): void | |||||
{ | |||||
$betas = \App\Sku::where('handler_class', 'like', '%\\Beta%')->pluck('id')->all(); | |||||
\App\Entitlement::whereIn('sku_id', $betas)->delete(); | |||||
} | |||||
/** | |||||
* Creates the application. | * Creates the application. | ||||
* | * | ||||
* @return \Illuminate\Foundation\Application | * @return \Illuminate\Foundation\Application | ||||
*/ | */ | ||||
public function createApplication() | public function createApplication() | ||||
{ | { | ||||
$app = require __DIR__ . '/../bootstrap/app.php'; | $app = require __DIR__ . '/../bootstrap/app.php'; | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |