Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCase.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use App\Domain; | use App\Domain; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
abstract class TestCase extends BaseTestCase | abstract class TestCase extends BaseTestCase | ||||
{ | { | ||||
use CreatesApplication; | use CreatesApplication; | ||||
protected function backdateEntitlements($entitlements, $targetDate) | |||||
{ | |||||
foreach ($entitlements as $entitlement) { | |||||
$entitlement->created_at = $targetDate; | |||||
$entitlement->updated_at = $targetDate; | |||||
$entitlement->save(); | |||||
} | |||||
} | |||||
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; | ||||
} | } | ||||
$job = new \App\Jobs\DomainDelete($domain); | $job = new \App\Jobs\DomainDelete($domain); | ||||
$job->handle(); | $job->handle(); | ||||
$domain->forceDelete(); | $domain->forceDelete(); | ||||
} | } | ||||
protected function deleteTestUser($email) | protected function deleteTestUser($email) | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = User::withTrashed()->where('email', $email)->first(); | $user = User::withTrashed()->where('email', $email)->first(); | ||||
if (!$user) { | if (!$user) { | ||||
return; | return; | ||||
} | } | ||||
$job = new \App\Jobs\UserDelete($user->id); | $job = new \App\Jobs\UserDelete($user->id); | ||||
$job->handle(); | $job->handle(); | ||||
Show All 15 Lines | abstract class TestCase extends BaseTestCase | ||||
/** | /** | ||||
* Get User object by email, create it if needed. | * Get User object by email, create it if needed. | ||||
* Skip LDAP jobs. | * Skip LDAP jobs. | ||||
*/ | */ | ||||
protected function getTestUser($email, $attrib = []) | protected function getTestUser($email, $attrib = []) | ||||
{ | { | ||||
// Disable jobs (i.e. skip LDAP oprations) | // Disable jobs (i.e. skip LDAP oprations) | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = User::withTrashed()->where('email', $email)->first(); | |||||
if (!$user) { | |||||
return User::firstOrCreate(['email' => $email], $attrib); | return User::firstOrCreate(['email' => $email], $attrib); | ||||
} | } | ||||
if ($user->deleted_at) { | |||||
$user->restore(); | |||||
} | |||||
return $user; | |||||
} | |||||
/** | /** | ||||
* Helper to access protected property of an object | * Helper to access protected property of an object | ||||
*/ | */ | ||||
protected static function getObjectProperty($object, $property_name) | protected static function getObjectProperty($object, $property_name) | ||||
{ | { | ||||
$reflection = new \ReflectionClass($object); | $reflection = new \ReflectionClass($object); | ||||
$property = $reflection->getProperty($property_name); | $property = $reflection->getProperty($property_name); | ||||
$property->setAccessible(true); | $property->setAccessible(true); | ||||
Show All 22 Lines |