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\User; | use App\User; | ||||
use Illuminate\Contracts\Console\Kernel; | use Illuminate\Contracts\Console\Kernel; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use PHPUnit\Framework\Assert; | |||||
trait TestCaseTrait | trait TestCaseTrait | ||||
{ | { | ||||
protected function assertUserEntitlements($user, $expected) | |||||
{ | |||||
// Assert the user entitlements | |||||
$skus = $user->entitlements()->get() | |||||
->map(function ($ent) { | |||||
return $ent->sku->title; | |||||
}) | |||||
->toArray(); | |||||
sort($skus); | |||||
Assert::assertSame($expected, $skus); | |||||
} | |||||
/** | /** | ||||
* 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 83 Lines • ▼ Show 20 Lines | trait TestCaseTrait | ||||
* Call protected/private method of a class. | * Call protected/private method of a class. | ||||
* | * | ||||
* @param object $object Instantiated object that we will run method on. | * @param object $object Instantiated object that we will run method on. | ||||
* @param string $methodName Method name to call | * @param string $methodName Method name to call | ||||
* @param array $parameters Array of parameters to pass into method. | * @param array $parameters Array of parameters to pass into method. | ||||
* | * | ||||
* @return mixed Method return. | * @return mixed Method return. | ||||
*/ | */ | ||||
public function invokeMethod($object, $methodName, array $parameters = array()) | protected function invokeMethod($object, $methodName, array $parameters = array()) | ||||
{ | { | ||||
$reflection = new \ReflectionClass(get_class($object)); | $reflection = new \ReflectionClass(get_class($object)); | ||||
$method = $reflection->getMethod($methodName); | $method = $reflection->getMethod($methodName); | ||||
$method->setAccessible(true); | $method->setAccessible(true); | ||||
return $method->invokeArgs($object, $parameters); | return $method->invokeArgs($object, $parameters); | ||||
} | } | ||||
} | } |