Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCaseTrait.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use App\Backends\IMAP; | |||||
use App\Backends\LDAP; | use App\Backends\LDAP; | ||||
use App\CompanionApp; | 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; | ||||
▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | 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; | ||||
} | } | ||||
if (\config('app.with_imap')) { | |||||
IMAP::deleteUser($user); | |||||
} | |||||
if (\config('app.with_ldap')) { | |||||
LDAP::deleteUser($user); | LDAP::deleteUser($user); | ||||
} | |||||
$user->forceDelete(); | $user->forceDelete(); | ||||
} | } | ||||
/** | /** | ||||
* Delete a test companion app whatever it takes. | * Delete a test companion app whatever it takes. | ||||
* | * | ||||
* @coversNothing | * @coversNothing | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | trait TestCaseTrait | ||||
} | } | ||||
/** | /** | ||||
* Get User object by email, create it if needed. | * Get User object by email, create it if needed. | ||||
* Skip LDAP jobs. | * Skip LDAP jobs. | ||||
* | * | ||||
* @coversNothing | * @coversNothing | ||||
*/ | */ | ||||
protected function getTestUser($email, $attrib = []) | protected function getTestUser($email, $attrib = [], $createInBackends = false) | ||||
{ | { | ||||
// Disable jobs (i.e. skip LDAP oprations) | // Disable jobs (i.e. skip LDAP oprations) | ||||
if (!$createInBackends) { | |||||
Queue::fake(); | Queue::fake(); | ||||
} | |||||
$user = User::firstOrCreate(['email' => $email], $attrib); | $user = User::firstOrCreate(['email' => $email], $attrib); | ||||
if ($user->trashed()) { | if ($user->trashed()) { | ||||
// Note: we do not want to use user restore here | // Note: we do not want to use user restore here | ||||
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; | ||||
mollekopf: I thought this works, but it doesn't.
phpunit seems to sometimes reinstantiate the entire… | |||||
} | } | ||||
/** | /** | ||||
* Get CompanionApp object by deviceId, create it if needed. | * Get CompanionApp object by deviceId, create it if needed. | ||||
* Skip LDAP jobs. | * Skip LDAP jobs. | ||||
* | * | ||||
* @coversNothing | * @coversNothing | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |
I thought this works, but it doesn't.
phpunit seems to sometimes reinstantiate the entire class between runs (member variables are lost), and beforeApplicationDestroyed is called on every tearDown().
So, phpunit makes it impossible to implement a setup first, run all tests, teardown last appraoch.
I'm going to stuff all tests into a single test function and be done with it.