Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCaseTrait.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use App\Backends\LDAP; | use App\Backends\LDAP; | ||||
use App\CompanionApp; | |||||
use App\Domain; | use App\Domain; | ||||
use App\Group; | use App\Group; | ||||
use App\Resource; | use App\Resource; | ||||
use App\SharedFolder; | use App\SharedFolder; | ||||
use App\Sku; | use App\Sku; | ||||
use App\Transaction; | use App\Transaction; | ||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | protected function deleteTestUser($email) | ||||
} | } | ||||
LDAP::deleteUser($user); | LDAP::deleteUser($user); | ||||
$user->forceDelete(); | $user->forceDelete(); | ||||
} | } | ||||
/** | /** | ||||
* Delete a test companion app whatever it takes. | |||||
* | |||||
* @coversNothing | |||||
*/ | |||||
protected function deleteTestCompanionApp($deviceId) | |||||
{ | |||||
Queue::fake(); | |||||
$companionApp = CompanionApp::where('device_id', $deviceId)->first(); | |||||
if (!$companionApp) { | |||||
return; | |||||
} | |||||
$companionApp->forceDelete(); | |||||
} | |||||
/** | |||||
* 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 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | protected function getTestUser($email, $attrib = []) | ||||
User::where('id', $user->id)->forceDelete(); | User::where('id', $user->id)->forceDelete(); | ||||
$user = User::create(['email' => $email] + $attrib); | $user = User::create(['email' => $email] + $attrib); | ||||
} | } | ||||
return $user; | return $user; | ||||
} | } | ||||
/** | /** | ||||
* Get CompanionApp object by deviceId, create it if needed. | |||||
* Skip LDAP jobs. | |||||
* | |||||
* @coversNothing | |||||
*/ | |||||
protected function getTestCompanionApp($deviceId, $user, $attrib = []) | |||||
{ | |||||
// Disable jobs (i.e. skip LDAP oprations) | |||||
Queue::fake(); | |||||
$companionApp = CompanionApp::firstOrCreate( | |||||
[ | |||||
'device_id' => $deviceId, | |||||
'user_id' => $user->id, | |||||
'notification_token' => '', | |||||
'mfa_enabled' => 1 | |||||
], | |||||
$attrib | |||||
); | |||||
return $companionApp; | |||||
} | |||||
/** | |||||
* 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. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |