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\Group; | use App\Group; | ||||
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. | * Assign 'meet' 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|\App\User $user The user | ||||
* @param string $sku The beta SKU title | |||||
*/ | */ | ||||
protected function assignBetaEntitlement($user, $sku): void | protected function assignMeetEntitlement($user): void | ||||
{ | { | ||||
if (is_string($user)) { | if (is_string($user)) { | ||||
$user = $this->getTestUser($user); | $user = $this->getTestUser($user); | ||||
} | } | ||||
$user->assignSku(\App\Sku::where('title', 'beta')->first()); | $user->assignSku(\App\Sku::where('title', 'meet')->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 | * Removes all beta entitlements from the database | ||||
*/ | */ | ||||
protected function clearBetaEntitlements(): void | protected function clearBetaEntitlements(): void | ||||
{ | { | ||||
$betas = \App\Sku::where('handler_class', 'like', '%\\Beta%')->pluck('id')->all(); | $betas = \App\Sku::where('handler_class', 'like', 'App\\Handlers\\Beta\\%') | ||||
->orWhere('handler_class', 'App\Handlers\Beta') | |||||
->pluck('id')->all(); | |||||
\App\Entitlement::whereIn('sku_id', $betas)->delete(); | \App\Entitlement::whereIn('sku_id', $betas)->delete(); | ||||
} | } | ||||
/** | /** | ||||
* Removes all 'meet' entitlements from the database | |||||
*/ | |||||
protected function clearMeetEntitlements(): void | |||||
{ | |||||
$meet_sku = \App\Sku::where('title', 'meet')->first(); | |||||
\App\Entitlement::where('sku_id', $meet_sku->id)->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 193 Lines • Show Last 20 Lines |