Page MenuHomePhorge

D5169.1775318611.diff
No OneTemporary

Authored By
Unknown
Size
44 KB
Referenced Files
None
Subscribers
None

D5169.1775318611.diff

diff --git a/src/app/Console/Commands/JobExecuteCommand.php b/src/app/Console/Commands/JobExecuteCommand.php
--- a/src/app/Console/Commands/JobExecuteCommand.php
+++ b/src/app/Console/Commands/JobExecuteCommand.php
@@ -46,7 +46,6 @@
$job = 'App\\Jobs\\' . $job;
- $job = new $job($object->id);
- $job->handle();
+ $job::dispatchSync($object->id);
}
}
diff --git a/src/app/Console/Commands/Resource/VerifyCommand.php b/src/app/Console/Commands/Resource/VerifyCommand.php
--- a/src/app/Console/Commands/Resource/VerifyCommand.php
+++ b/src/app/Console/Commands/Resource/VerifyCommand.php
@@ -34,8 +34,7 @@
return 1;
}
- $job = new \App\Jobs\Resource\VerifyJob($resource->id);
- $job->handle();
+ \App\Jobs\Resource\VerifyJob::dispatchSync($resource->id);
// TODO: We should check the job result and print an error on failure
}
diff --git a/src/app/Console/Commands/User/VerifyCommand.php b/src/app/Console/Commands/User/VerifyCommand.php
--- a/src/app/Console/Commands/User/VerifyCommand.php
+++ b/src/app/Console/Commands/User/VerifyCommand.php
@@ -34,8 +34,7 @@
return 1;
}
- $job = new \App\Jobs\User\VerifyJob($user->id);
- $job->handle();
+ \App\Jobs\User\VerifyJob::dispatchSync($user->id);
// TODO: We should check the job result and print an error on failure
}
diff --git a/src/app/Http/Controllers/API/V4/GroupsController.php b/src/app/Http/Controllers/API/V4/GroupsController.php
--- a/src/app/Http/Controllers/API/V4/GroupsController.php
+++ b/src/app/Http/Controllers/API/V4/GroupsController.php
@@ -214,12 +214,8 @@
switch ($step) {
case 'distlist-ldap-ready':
// Group not in LDAP, create it
- $job = new \App\Jobs\Group\CreateJob($group->id);
- $job->handle();
-
- $group->refresh();
-
- return $group->isLdapReady();
+ \App\Jobs\Group\CreateJob::dispatch($group->id);
+ return null;
}
} catch (\Exception $e) {
\Log::error($e);
diff --git a/src/app/Jobs/CommonJob.php b/src/app/Jobs/CommonJob.php
--- a/src/app/Jobs/CommonJob.php
+++ b/src/app/Jobs/CommonJob.php
@@ -17,32 +17,7 @@
use InteractsWithQueue;
use Queueable;
- /**
- * The failure message.
- *
- * @var string
- */
- public $failureMessage;
-
- /**
- * The job deleted state.
- *
- * @var bool
- */
- protected $isDeleted = false;
-
- /**
- * The job released state.
- *
- * @var bool
- */
- protected $isReleased = false;
-
- /**
- * The number of tries for this Job.
- *
- * @var int
- */
+ /** @var int The number of tries for this Job */
public $tries = 24;
/**
@@ -62,88 +37,6 @@
return [5, 15, 60, 300, 3600];
}
- /**
- * Delete the job from the queue.
- *
- * @return void
- */
- public function delete()
- {
- // We need this for testing purposes
- $this->isDeleted = true;
-
- if ($this->job) {
- $this->job->delete();
- }
- }
-
- /**
- * Delete the job, call the "failed" method, and raise the failed job event.
- *
- * @param \Throwable|null $e An Exception
- *
- * @return void
- */
- public function fail($e = null)
- {
- // Save the message, for testing purposes
- $this->failureMessage = $e->getMessage();
-
- if ($this->job) {
- $this->job->fail($e);
- }
- }
-
- /**
- * Check if the job has failed
- *
- * @return bool
- */
- public function hasFailed(): bool
- {
- return $this->failureMessage !== null;
- }
-
- /**
- * Release the job back into the queue.
- *
- * @param int $delay Time in seconds
- * @return void
- */
- public function release($delay = 0)
- {
- // We need this for testing purposes
- $this->isReleased = true;
-
- if ($this->job) {
- $this->job->release($delay);
- } else {
- // $this->job is only set when the job is dispatched, not if manually executed by calling handle().
- // When manually executed, release() does nothing, and we thus throw an exception.
- throw new \Exception("Attempted to release a manually executed job");
- }
- }
-
- /**
- * Determine if the job has been deleted.
- *
- * @return bool
- */
- public function isDeleted(): bool
- {
- return $this->isDeleted;
- }
-
- /**
- * Check if the job was released
- *
- * @return bool
- */
- public function isReleased(): bool
- {
- return $this->isReleased;
- }
-
/**
* Log human-readable job title (at least contains job class name)
*/
diff --git a/src/app/Jobs/Domain/DeleteJob.php b/src/app/Jobs/Domain/DeleteJob.php
--- a/src/app/Jobs/Domain/DeleteJob.php
+++ b/src/app/Jobs/Domain/DeleteJob.php
@@ -21,12 +21,12 @@
// sanity checks
if (!$domain->trashed()) {
- $this->fail(new \Exception("Domain {$this->domainId} is not deleted."));
+ $this->fail("Domain {$this->domainId} is not deleted.");
return;
}
if ($domain->isDeleted()) {
- $this->fail(new \Exception("Domain {$this->domainId} is already marked as deleted."));
+ $this->fail("Domain {$this->domainId} is already marked as deleted.");
return;
}
diff --git a/src/app/Jobs/DomainJob.php b/src/app/Jobs/DomainJob.php
--- a/src/app/Jobs/DomainJob.php
+++ b/src/app/Jobs/DomainJob.php
@@ -65,7 +65,7 @@
return null;
}
- $this->fail(new \Exception("Domain {$this->domainId} could not be found in the database."));
+ $this->fail("Domain {$this->domainId} could not be found in the database.");
}
return $domain;
diff --git a/src/app/Jobs/Group/DeleteJob.php b/src/app/Jobs/Group/DeleteJob.php
--- a/src/app/Jobs/Group/DeleteJob.php
+++ b/src/app/Jobs/Group/DeleteJob.php
@@ -21,12 +21,12 @@
// sanity checks
if (!$group->trashed()) {
- $this->fail(new \Exception("Group {$this->groupId} is not deleted."));
+ $this->fail("Group {$this->groupId} is not deleted.");
return;
}
if ($group->isDeleted()) {
- $this->fail(new \Exception("Group {$this->groupId} is already marked as deleted."));
+ $this->fail("Group {$this->groupId} is already marked as deleted.");
return;
}
diff --git a/src/app/Jobs/GroupJob.php b/src/app/Jobs/GroupJob.php
--- a/src/app/Jobs/GroupJob.php
+++ b/src/app/Jobs/GroupJob.php
@@ -65,7 +65,7 @@
return null;
}
- $this->fail(new \Exception("Group {$this->groupId} could not be found in the database."));
+ $this->fail("Group {$this->groupId} could not be found in the database.");
}
return $group;
diff --git a/src/app/Jobs/PGP/KeyCreateJob.php b/src/app/Jobs/PGP/KeyCreateJob.php
--- a/src/app/Jobs/PGP/KeyCreateJob.php
+++ b/src/app/Jobs/PGP/KeyCreateJob.php
@@ -47,12 +47,12 @@
// sanity checks
if ($user->isDeleted()) {
- $this->fail(new \Exception("User {$this->userId} is marked as deleted."));
+ $this->fail("User {$this->userId} is marked as deleted.");
return;
}
if ($user->trashed()) {
- $this->fail(new \Exception("User {$this->userId} is actually deleted."));
+ $this->fail("User {$this->userId} is actually deleted.");
return;
}
@@ -60,7 +60,7 @@
$this->userEmail != $user->email
&& !$user->aliases()->where('alias', $this->userEmail)->exists()
) {
- $this->fail(new \Exception("Alias {$this->userEmail} is actually deleted."));
+ $this->fail("Alias {$this->userEmail} is actually deleted.");
return;
}
diff --git a/src/app/Jobs/Resource/CreateJob.php b/src/app/Jobs/Resource/CreateJob.php
--- a/src/app/Jobs/Resource/CreateJob.php
+++ b/src/app/Jobs/Resource/CreateJob.php
@@ -21,12 +21,12 @@
// sanity checks
if ($resource->isDeleted()) {
- $this->fail(new \Exception("Resource {$this->resourceId} is marked as deleted."));
+ $this->fail("Resource {$this->resourceId} is marked as deleted.");
return;
}
if ($resource->trashed()) {
- $this->fail(new \Exception("Resource {$this->resourceId} is actually deleted."));
+ $this->fail("Resource {$this->resourceId} is actually deleted.");
return;
}
@@ -36,12 +36,12 @@
$domain = $resource->domain();
if (!$domain) {
- $this->fail(new \Exception("The domain for resource {$this->resourceId} does not exist."));
+ $this->fail("The domain for resource {$this->resourceId} does not exist.");
return;
}
if ($domain->isDeleted()) {
- $this->fail(new \Exception("The domain for resource {$this->resourceId} is marked as deleted."));
+ $this->fail("The domain for resource {$this->resourceId} is marked as deleted.");
return;
}
diff --git a/src/app/Jobs/Resource/DeleteJob.php b/src/app/Jobs/Resource/DeleteJob.php
--- a/src/app/Jobs/Resource/DeleteJob.php
+++ b/src/app/Jobs/Resource/DeleteJob.php
@@ -21,12 +21,12 @@
// sanity checks
if (!$resource->trashed()) {
- $this->fail(new \Exception("Resource {$this->resourceId} is not deleted."));
+ $this->fail("Resource {$this->resourceId} is not deleted.");
return;
}
if ($resource->isDeleted()) {
- $this->fail(new \Exception("Resource {$this->resourceId} is already marked as deleted."));
+ $this->fail("Resource {$this->resourceId} is already marked as deleted.");
return;
}
diff --git a/src/app/Jobs/Resource/VerifyJob.php b/src/app/Jobs/Resource/VerifyJob.php
--- a/src/app/Jobs/Resource/VerifyJob.php
+++ b/src/app/Jobs/Resource/VerifyJob.php
@@ -21,7 +21,7 @@
// the resource was already verified
if ($resource->isImapReady()) {
- $this->fail(new \Exception("Resource {$this->resourceId} is already verified."));
+ $this->fail("Resource {$this->resourceId} is already verified.");
return;
}
diff --git a/src/app/Jobs/ResourceJob.php b/src/app/Jobs/ResourceJob.php
--- a/src/app/Jobs/ResourceJob.php
+++ b/src/app/Jobs/ResourceJob.php
@@ -74,7 +74,7 @@
return null;
}
- $this->fail(new \Exception("Resource {$this->resourceId} could not be found in the database."));
+ $this->fail("Resource {$this->resourceId} could not be found in the database.");
}
return $resource;
diff --git a/src/app/Jobs/SharedFolder/CreateJob.php b/src/app/Jobs/SharedFolder/CreateJob.php
--- a/src/app/Jobs/SharedFolder/CreateJob.php
+++ b/src/app/Jobs/SharedFolder/CreateJob.php
@@ -21,12 +21,12 @@
// sanity checks
if ($folder->isDeleted()) {
- $this->fail(new \Exception("Shared folder {$this->folderId} is marked as deleted."));
+ $this->fail("Shared folder {$this->folderId} is marked as deleted.");
return;
}
if ($folder->trashed()) {
- $this->fail(new \Exception("Shared folder {$this->folderId} is actually deleted."));
+ $this->fail("Shared folder {$this->folderId} is actually deleted.");
return;
}
@@ -36,12 +36,12 @@
$domain = $folder->domain();
if (!$domain) {
- $this->fail(new \Exception("The domain for shared folder {$this->folderId} does not exist."));
+ $this->fail("The domain for shared folder {$this->folderId} does not exist.");
return;
}
if ($domain->isDeleted()) {
- $this->fail(new \Exception("The domain for shared folder {$this->folderId} is marked as deleted."));
+ $this->fail("The domain for shared folder {$this->folderId} is marked as deleted.");
return;
}
diff --git a/src/app/Jobs/SharedFolder/DeleteJob.php b/src/app/Jobs/SharedFolder/DeleteJob.php
--- a/src/app/Jobs/SharedFolder/DeleteJob.php
+++ b/src/app/Jobs/SharedFolder/DeleteJob.php
@@ -21,12 +21,12 @@
// sanity checks
if (!$folder->trashed()) {
- $this->fail(new \Exception("Shared folder {$this->folderId} is not deleted."));
+ $this->fail("Shared folder {$this->folderId} is not deleted.");
return;
}
if ($folder->isDeleted()) {
- $this->fail(new \Exception("Shared folder {$this->folderId} is already marked as deleted."));
+ $this->fail("Shared folder {$this->folderId} is already marked as deleted.");
return;
}
diff --git a/src/app/Jobs/SharedFolder/VerifyJob.php b/src/app/Jobs/SharedFolder/VerifyJob.php
--- a/src/app/Jobs/SharedFolder/VerifyJob.php
+++ b/src/app/Jobs/SharedFolder/VerifyJob.php
@@ -21,7 +21,7 @@
// the user has a mailbox (or is marked as such)
if ($folder->isImapReady()) {
- $this->fail(new \Exception("Shared folder {$this->folderId} is already verified."));
+ $this->fail("Shared folder {$this->folderId} is already verified.");
return;
}
diff --git a/src/app/Jobs/SharedFolderJob.php b/src/app/Jobs/SharedFolderJob.php
--- a/src/app/Jobs/SharedFolderJob.php
+++ b/src/app/Jobs/SharedFolderJob.php
@@ -73,7 +73,7 @@
return null;
}
- $this->fail(new \Exception("Shared folder {$this->folderId} could not be found in the database."));
+ $this->fail("Shared folder {$this->folderId} could not be found in the database.");
}
return $folder;
diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php
--- a/src/app/Jobs/User/CreateJob.php
+++ b/src/app/Jobs/User/CreateJob.php
@@ -48,12 +48,12 @@
// sanity checks
if ($user->isDeleted()) {
- $this->fail(new \Exception("User {$this->userId} is marked as deleted."));
+ $this->fail("User {$this->userId} is marked as deleted.");
return;
}
if ($user->trashed()) {
- $this->fail(new \Exception("User {$this->userId} is actually deleted."));
+ $this->fail("User {$this->userId} is actually deleted.");
return;
}
@@ -63,12 +63,12 @@
$domain = $user->domain();
if (!$domain) {
- $this->fail(new \Exception("The domain for {$this->userId} does not exist."));
+ $this->fail("The domain for {$this->userId} does not exist.");
return;
}
if ($domain->isDeleted()) {
- $this->fail(new \Exception("The domain for {$this->userId} is marked as deleted."));
+ $this->fail("The domain for {$this->userId} is marked as deleted.");
return;
}
diff --git a/src/app/Jobs/User/DeleteJob.php b/src/app/Jobs/User/DeleteJob.php
--- a/src/app/Jobs/User/DeleteJob.php
+++ b/src/app/Jobs/User/DeleteJob.php
@@ -27,13 +27,13 @@
}
if (!$user->trashed()) {
- $this->fail(new \Exception("User {$this->userId} is not deleted."));
+ $this->fail("User {$this->userId} is not deleted.");
return;
}
// sanity checks
if ($user->isDeleted()) {
- $this->fail(new \Exception("User {$this->userId} is already marked as deleted."));
+ $this->fail("User {$this->userId} is already marked as deleted.");
return;
}
diff --git a/src/app/Jobs/User/ResyncJob.php b/src/app/Jobs/User/ResyncJob.php
--- a/src/app/Jobs/User/ResyncJob.php
+++ b/src/app/Jobs/User/ResyncJob.php
@@ -42,8 +42,7 @@
$domain->status &= ~Domain::STATUS_LDAP_READY;
$domain->save();
- $job = new \App\Jobs\Domain\CreateJob($domain->id);
- $job->handle();
+ \App\Jobs\Domain\CreateJob::dispatchSync($domain->id);
}
if (!LDAP::getUser($user->email)) {
@@ -62,7 +61,6 @@
$user->update();
- $job = new $userJob($user->id);
- $job->handle();
+ $userJob::dispatchSync($user->id);
}
}
diff --git a/src/app/Jobs/User/VerifyJob.php b/src/app/Jobs/User/VerifyJob.php
--- a/src/app/Jobs/User/VerifyJob.php
+++ b/src/app/Jobs/User/VerifyJob.php
@@ -28,13 +28,13 @@
// sanity checks
if (!$user->hasSku('mailbox')) {
- $this->fail(new \Exception("User {$this->userId} has no mailbox SKU."));
+ $this->fail("User {$this->userId} has no mailbox SKU.");
return;
}
// the user has a mailbox (or is marked as such)
if ($user->isImapReady()) {
- $this->fail(new \Exception("User {$this->userId} is already verified."));
+ $this->fail("User {$this->userId} is already verified.");
return;
}
diff --git a/src/app/Jobs/UserJob.php b/src/app/Jobs/UserJob.php
--- a/src/app/Jobs/UserJob.php
+++ b/src/app/Jobs/UserJob.php
@@ -68,7 +68,7 @@
return null;
}
- $this->fail(new \Exception("User {$this->userId} could not be found in the database."));
+ $this->fail("User {$this->userId} could not be found in the database.");
}
return $user;
diff --git a/src/tests/Feature/Jobs/Domain/CreateTest.php b/src/tests/Feature/Jobs/Domain/CreateTest.php
--- a/src/tests/Feature/Jobs/Domain/CreateTest.php
+++ b/src/tests/Feature/Jobs/Domain/CreateTest.php
@@ -67,11 +67,10 @@
);
// Test job releasing on unknown identifier
- $this->expectException(\Exception::class);
- $job = new \App\Jobs\Domain\CreateJob(123);
+ $job = (new \App\Jobs\Domain\CreateJob(123))->withFakeQueueInteractions();
$job->handle();
+ $job->assertReleased(delay: 5);
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ // TODO: the job can't be released infinitely (?), test that
}
}
diff --git a/src/tests/Feature/Jobs/Domain/VerifyTest.php b/src/tests/Feature/Jobs/Domain/VerifyTest.php
--- a/src/tests/Feature/Jobs/Domain/VerifyTest.php
+++ b/src/tests/Feature/Jobs/Domain/VerifyTest.php
@@ -49,11 +49,9 @@
$this->assertTrue($domain->fresh()->isVerified());
// Test non-existing domain ID
- $job = new \App\Jobs\Domain\VerifyJob(123);
+ $job = (new \App\Jobs\Domain\VerifyJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Domain 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Domain 123 could not be found in the database.");
}
/**
diff --git a/src/tests/Feature/Jobs/Group/CreateTest.php b/src/tests/Feature/Jobs/Group/CreateTest.php
--- a/src/tests/Feature/Jobs/Group/CreateTest.php
+++ b/src/tests/Feature/Jobs/Group/CreateTest.php
@@ -47,11 +47,8 @@
}
// Test non-existing group ID
- $this->expectException(\Exception::class);
- $job = new \App\Jobs\Group\CreateJob(123);
+ $job = (new \App\Jobs\Group\CreateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ $job->assertReleased(delay: 5);
}
}
diff --git a/src/tests/Feature/Jobs/Group/DeleteTest.php b/src/tests/Feature/Jobs/Group/DeleteTest.php
--- a/src/tests/Feature/Jobs/Group/DeleteTest.php
+++ b/src/tests/Feature/Jobs/Group/DeleteTest.php
@@ -50,11 +50,9 @@
}
// Test group that is not deleted yet
- $job = new \App\Jobs\Group\DeleteJob($group->id);
+ $job = (new \App\Jobs\Group\DeleteJob($group->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Group {$group->id} is not deleted.", $job->failureMessage);
+ $job->assertFailedWith("Group {$group->id} is not deleted.");
$group->deleted_at = \now();
$group->saveQuietly();
@@ -82,10 +80,8 @@
);
*/
// Test non-existing group ID
- $job = new \App\Jobs\Group\DeleteJob(123);
+ $job = (new \App\Jobs\Group\DeleteJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Group 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Group 123 could not be found in the database.");
}
}
diff --git a/src/tests/Feature/Jobs/Group/UpdateTest.php b/src/tests/Feature/Jobs/Group/UpdateTest.php
--- a/src/tests/Feature/Jobs/Group/UpdateTest.php
+++ b/src/tests/Feature/Jobs/Group/UpdateTest.php
@@ -36,20 +36,17 @@
Queue::fake();
// Test non-existing group ID
- $job = new \App\Jobs\Group\UpdateJob(123);
+ $job = (new \App\Jobs\Group\UpdateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Group 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Group 123 could not be found in the database.");
// Create the group
$group = $this->getTestGroup('group@kolab.org', ['members' => []]);
if (!\config('app.with_ldap')) {
- $job = new \App\Jobs\Group\UpdateJob($group->id);
+ $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isDeleted());
+ $job->assertDeleted();
$this->markTestSkipped();
}
diff --git a/src/tests/Feature/Jobs/Resource/CreateTest.php b/src/tests/Feature/Jobs/Resource/CreateTest.php
--- a/src/tests/Feature/Jobs/Resource/CreateTest.php
+++ b/src/tests/Feature/Jobs/Resource/CreateTest.php
@@ -36,12 +36,9 @@
Queue::fake();
// Test unknown resource
- $this->expectException(\Exception::class);
- $job = new \App\Jobs\Resource\CreateJob(123);
+ $job = (new \App\Jobs\Resource\CreateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ $job->assertReleased();
$resource = $this->getTestResource(
'resource-test@' . \config('app.domain'),
@@ -53,12 +50,12 @@
$this->assertFalse($resource->isActive());
// Test resource creation
- $job = new \App\Jobs\Resource\CreateJob($resource->id);
+ $job = (new \App\Jobs\Resource\CreateJob($resource->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$resource->refresh();
- $this->assertFalse($job->hasFailed());
$this->assertSame(\config('app.with_ldap'), $resource->isLdapReady());
$this->assertTrue($resource->isImapReady());
$this->assertTrue($resource->isActive());
@@ -67,21 +64,17 @@
$resource->status |= Resource::STATUS_DELETED;
$resource->save();
- $job = new \App\Jobs\Resource\CreateJob($resource->id);
+ $job = (new \App\Jobs\Resource\CreateJob($resource->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource {$resource->id} is marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("Resource {$resource->id} is marked as deleted.");
$resource->status ^= Resource::STATUS_DELETED;
$resource->save();
$resource->delete();
- $job = new \App\Jobs\Resource\CreateJob($resource->id);
+ $job = (new \App\Jobs\Resource\CreateJob($resource->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource {$resource->id} is actually deleted.", $job->failureMessage);
+ $job->assertFailedWith("Resource {$resource->id} is actually deleted.");
// TODO: Test failures on domain sanity checks
// TODO: Test partial execution, i.e. only IMAP or only LDAP
diff --git a/src/tests/Feature/Jobs/Resource/DeleteTest.php b/src/tests/Feature/Jobs/Resource/DeleteTest.php
--- a/src/tests/Feature/Jobs/Resource/DeleteTest.php
+++ b/src/tests/Feature/Jobs/Resource/DeleteTest.php
@@ -36,11 +36,9 @@
Queue::fake();
// Test non-existing resource ID
- $job = new \App\Jobs\Resource\DeleteJob(123);
+ $job = (new \App\Jobs\Resource\DeleteJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Resource 123 could not be found in the database.");
$resource = $this->getTestResource('resource-test@' . \config('app.domain'), [
'status' => Resource::STATUS_NEW
@@ -57,11 +55,9 @@
$this->assertFalse($resource->isDeleted());
// Test deleting not deleted resource
- $job = new \App\Jobs\Resource\DeleteJob($resource->id);
+ $job = (new \App\Jobs\Resource\DeleteJob($resource->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource {$resource->id} is not deleted.", $job->failureMessage);
+ $job->assertFailedWith("Resource {$resource->id} is not deleted.");
$resource->deleted_at = \now();
$resource->saveQuietly();
@@ -80,10 +76,8 @@
Queue::assertPushed(\App\Jobs\Resource\UpdateJob::class, 0);
// Test deleting already deleted resource
- $job = new \App\Jobs\Resource\DeleteJob($resource->id);
+ $job = (new \App\Jobs\Resource\DeleteJob($resource->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource {$resource->id} is already marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("Resource {$resource->id} is already marked as deleted.");
}
}
diff --git a/src/tests/Feature/Jobs/Resource/UpdateTest.php b/src/tests/Feature/Jobs/Resource/UpdateTest.php
--- a/src/tests/Feature/Jobs/Resource/UpdateTest.php
+++ b/src/tests/Feature/Jobs/Resource/UpdateTest.php
@@ -40,11 +40,9 @@
Queue::fake();
// Test non-existing resource ID
- $job = new \App\Jobs\Resource\UpdateJob(123);
+ $job = (new \App\Jobs\Resource\UpdateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Resource 123 could not be found in the database.");
$resource = $this->getTestResource(
'resource-test@' . \config('app.domain'),
@@ -74,9 +72,8 @@
$resource->status |= Resource::STATUS_DELETED;
$resource->save();
- $job = new \App\Jobs\Resource\UpdateJob($resource->id);
+ $job = (new \App\Jobs\Resource\UpdateJob($resource->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isDeleted());
+ $job->assertDeleted();
}
}
diff --git a/src/tests/Feature/Jobs/Resource/VerifyTest.php b/src/tests/Feature/Jobs/Resource/VerifyTest.php
--- a/src/tests/Feature/Jobs/Resource/VerifyTest.php
+++ b/src/tests/Feature/Jobs/Resource/VerifyTest.php
@@ -42,11 +42,9 @@
Queue::fake();
// Test non-existing resource ID
- $job = new \App\Jobs\Resource\VerifyJob(123);
+ $job = (new \App\Jobs\Resource\VerifyJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Resource 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Resource 123 could not be found in the database.");
// Test existing resource
$resource = $this->getTestResource('resource-test1@kolab.org');
diff --git a/src/tests/Feature/Jobs/SharedFolder/CreateTest.php b/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
@@ -36,12 +36,9 @@
Queue::fake();
// Test unknown folder
- $this->expectException(\Exception::class);
- $job = new \App\Jobs\SharedFolder\CreateJob(123);
+ $job = (new \App\Jobs\SharedFolder\CreateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ $job->assertReleased(delay: 5);
$folder = $this->getTestSharedFolder(
'folder-test@' . \config('app.domain'),
@@ -53,12 +50,12 @@
$this->assertFalse($folder->isActive());
// Test shared folder creation
- $job = new \App\Jobs\SharedFolder\CreateJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\CreateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$folder->refresh();
- $this->assertFalse($job->hasFailed());
if (\config('app.with_ldap')) {
$this->assertTrue($folder->isLdapReady());
} else {
@@ -75,21 +72,17 @@
$folder->status |= SharedFolder::STATUS_DELETED;
$folder->save();
- $job = new \App\Jobs\SharedFolder\CreateJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\CreateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder {$folder->id} is marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder {$folder->id} is marked as deleted.");
$folder->status ^= SharedFolder::STATUS_DELETED;
$folder->save();
$folder->delete();
- $job = new \App\Jobs\SharedFolder\CreateJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\CreateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder {$folder->id} is actually deleted.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder {$folder->id} is actually deleted.");
// TODO: Test failures on domain sanity checks
// TODO: Test partial execution, i.e. only IMAP or only LDAP
diff --git a/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php b/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
@@ -36,11 +36,9 @@
Queue::fake();
// Test non-existing folder ID
- $job = new \App\Jobs\SharedFolder\DeleteJob(123);
+ $job = (new \App\Jobs\SharedFolder\DeleteJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder 123 could not be found in the database.");
$folder = $this->getTestSharedFolder('folder-test@' . \config('app.domain'), [
'status' => SharedFolder::STATUS_NEW
@@ -61,11 +59,9 @@
$this->assertFalse($folder->isDeleted());
// Test deleting not deleted folder
- $job = new \App\Jobs\SharedFolder\DeleteJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\DeleteJob($folder->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder {$folder->id} is not deleted.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder {$folder->id} is not deleted.");
$folder->deleted_at = \now();
$folder->saveQuietly();
@@ -84,10 +80,8 @@
Queue::assertPushed(\App\Jobs\SharedFolder\UpdateJob::class, 0);
// Test deleting already deleted folder
- $job = new \App\Jobs\SharedFolder\DeleteJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\DeleteJob($folder->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder {$folder->id} is already marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder {$folder->id} is already marked as deleted.");
}
}
diff --git a/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php b/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
@@ -40,11 +40,9 @@
Queue::fake();
// Test non-existing folder ID
- $job = new \App\Jobs\SharedFolder\UpdateJob(123);
+ $job = (new \App\Jobs\SharedFolder\UpdateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder 123 could not be found in the database.");
$folder = $this->getTestSharedFolder(
'folder-test@' . \config('app.domain'),
@@ -65,8 +63,9 @@
$this->assertTrue($folder->isImapReady());
// Run the update job
- $job = new \App\Jobs\SharedFolder\UpdateJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\UpdateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
// TODO: Assert that it worked on both LDAP and IMAP side
@@ -74,9 +73,8 @@
$folder->status |= SharedFolder::STATUS_DELETED;
$folder->save();
- $job = new \App\Jobs\SharedFolder\UpdateJob($folder->id);
+ $job = (new \App\Jobs\SharedFolder\UpdateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isDeleted());
+ $job->assertDeleted();
}
}
diff --git a/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php b/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
@@ -42,11 +42,9 @@
Queue::fake();
// Test non-existing folder ID
- $job = new \App\Jobs\SharedFolder\VerifyJob(123);
+ $job = (new \App\Jobs\SharedFolder\VerifyJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("Shared folder 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("Shared folder 123 could not be found in the database.");
// Test existing folder
$folder = $this->getTestSharedFolder('folder-event@kolab.org');
diff --git a/src/tests/Feature/Jobs/User/CreateTest.php b/src/tests/Feature/Jobs/User/CreateTest.php
--- a/src/tests/Feature/Jobs/User/CreateTest.php
+++ b/src/tests/Feature/Jobs/User/CreateTest.php
@@ -34,6 +34,7 @@
public function testHandle(): void
{
Queue::fake();
+
$user = $this->getTestUser('new-job-user@' . \config('app.domain'), ['status' => User::STATUS_NEW]);
$domain = \App\Domain::where('namespace', \config('app.domain'))->first();
$domain->status |= \App\Domain::STATUS_LDAP_READY;
@@ -44,8 +45,9 @@
$this->assertFalse($user->isImapReady());
$this->assertFalse($user->isActive());
- $job = new \App\Jobs\User\CreateJob($user->id);
+ $job = (new \App\Jobs\User\CreateJob($user->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$user->refresh();
@@ -60,37 +62,28 @@
$this->assertFalse($user->isImapReady());
}
$this->assertTrue($user->isActive());
- $this->assertFalse($job->hasFailed());
// Test job failure (user deleted)
$user->status |= User::STATUS_DELETED;
$user->save();
- $job = new \App\Jobs\User\CreateJob($user->id);
+ $job = (new \App\Jobs\User\CreateJob($user->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("User {$user->id} is marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("User {$user->id} is marked as deleted.");
// Test job failure (user removed)
$user->status ^= User::STATUS_DELETED;
$user->save();
$user->delete();
- $job = new \App\Jobs\User\CreateJob($user->id);
+ $job = (new \App\Jobs\User\CreateJob($user->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertFailedWith("User {$user->id} is actually deleted.");
- $this->assertTrue($job->hasFailed());
- $this->assertSame("User {$user->id} is actually deleted.", $job->failureMessage);
-
- // Test job failure (user unknown)
- // The job will be released
- $this->expectException(\Exception::class);
- $job = new \App\Jobs\User\CreateJob(123);
+ // Test job failure (user unknown), the job will be released
+ $job = (new \App\Jobs\User\CreateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ $job->assertReleased(delay: 5);
// TODO: Test failures on domain sanity checks
// TODO: Test partial execution, i.e. only IMAP or only LDAP
diff --git a/src/tests/Feature/Jobs/User/DeleteTest.php b/src/tests/Feature/Jobs/User/DeleteTest.php
--- a/src/tests/Feature/Jobs/User/DeleteTest.php
+++ b/src/tests/Feature/Jobs/User/DeleteTest.php
@@ -45,12 +45,8 @@
$user = $this->getTestUser('new-job-user@' . \config('app.domain'));
$rcuser = Roundcube::userId($user->email);
- try {
- $job = new \App\Jobs\User\CreateJob($user->id);
- $job->handle();
- } catch (\Exception $e) {
- // Ignore "Attempted to release a manually executed job" exception
- }
+ $job = new \App\Jobs\User\CreateJob($user->id);
+ $job->handle();
$user->refresh();
@@ -60,22 +56,18 @@
$this->assertNotNull($rcdb->table('users')->where('username', $user->email)->first());
// Test job failure (user not yet deleted)
- $job = new \App\Jobs\User\DeleteJob($user->id);
+ $job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("User {$user->id} is not deleted.", $job->failureMessage);
+ $job->assertFailedWith("User {$user->id} is not deleted.");
// Test job failure (user already deleted)
$user->status |= User::STATUS_DELETED;
$user->deleted_at = \now();
$user->saveQuietly();
- $job = new \App\Jobs\User\DeleteJob($user->id);
+ $job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("User {$user->id} is already marked as deleted.", $job->failureMessage);
+ $job->assertFailedWith("User {$user->id} is already marked as deleted.");
// Test success delete from LDAP, IMAP and Roundcube
$user->status ^= User::STATUS_DELETED;
@@ -90,12 +82,12 @@
// in the same second. If that's the case IMAP DELETE will fail. So, let's wait a second.
sleep(1);
- $job = new \App\Jobs\User\DeleteJob($user->id);
+ $job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$user->refresh();
- $this->assertFalse($job->hasFailed());
$this->assertFalse($user->isLdapReady());
$this->assertFalse($user->isImapReady());
$this->assertTrue($user->isDeleted());
diff --git a/src/tests/Feature/Jobs/User/ResyncTest.php b/src/tests/Feature/Jobs/User/ResyncTest.php
--- a/src/tests/Feature/Jobs/User/ResyncTest.php
+++ b/src/tests/Feature/Jobs/User/ResyncTest.php
@@ -55,6 +55,8 @@
$this->assertTrue(empty(LDAP::getUser($user->email)));
}
+ Queue::fake();
+
// Test a user (and custom domain) that both aren't in ldap (despite their status)
$job = new \App\Jobs\User\ResyncJob($user->id);
$job->handle();
@@ -62,16 +64,29 @@
$user->refresh();
$domain->refresh();
- $this->assertTrue($user->isLdapReady());
- $this->assertTrue($domain->isLdapReady());
- $this->assertTrue($user->isImapReady());
- $this->assertTrue(IMAP::verifyAccount($user->email));
-
if (\config('app.with_ldap')) {
- $this->assertTrue(!empty(LDAP::getDomain($domain->namespace)));
- $this->assertTrue(!empty(LDAP::getUser($user->email)));
+ $this->assertFalse($user->isLdapReady());
+ $this->assertFalse($domain->isLdapReady());
+
+ Queue::assertPushed(\App\Jobs\Domain\CreateJob::class, 1);
+ Queue::assertPushed(
+ \App\Jobs\Domain\CreateJob::class,
+ function ($job) use ($domain) {
+ return $domain->id == TestCase::getObjectProperty($job, 'domainId');
+ }
+ );
}
- // TODO: More tests cases
+ $this->assertFalse($user->isImapReady());
+
+ Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1);
+ Queue::assertPushed(
+ \App\Jobs\User\CreateJob::class,
+ function ($job) use ($user) {
+ return $user->id == TestCase::getObjectProperty($job, 'userId');
+ }
+ );
+
+ // TODO: More cases
}
}
diff --git a/src/tests/Feature/Jobs/User/UpdateTest.php b/src/tests/Feature/Jobs/User/UpdateTest.php
--- a/src/tests/Feature/Jobs/User/UpdateTest.php
+++ b/src/tests/Feature/Jobs/User/UpdateTest.php
@@ -42,12 +42,7 @@
$user = $this->getTestUser('new-job-user@' . \config('app.domain'));
- try {
- $job = new \App\Jobs\User\CreateJob($user->id);
- $job->handle();
- } catch (\Exception $e) {
- // Ignore "Attempted to release a manually executed job" exception
- }
+ \App\Jobs\User\CreateJob::dispatchSync($user->id);
// Test setting two aliases
$aliases = [
@@ -97,19 +92,14 @@
// Test deleted user
$user->delete();
- $job = new UpdateJob($user->id);
+ $job = (new UpdateJob($user->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertDeleted();
- $this->assertTrue($job->isDeleted());
-
- // Test job failure (user unknown)
- // The job will be released
- $this->expectException(\Exception::class);
- $job = new UpdateJob(123);
+ // Test job failure (user unknown), the job will be released
+ $job = (new UpdateJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->isReleased());
- $this->assertFalse($job->hasFailed());
+ $job->assertReleased(delay: 5);
// TODO: Test IMAP, e.g. quota change
}
diff --git a/src/tests/Feature/Jobs/User/VerifyTest.php b/src/tests/Feature/Jobs/User/VerifyTest.php
--- a/src/tests/Feature/Jobs/User/VerifyTest.php
+++ b/src/tests/Feature/Jobs/User/VerifyTest.php
@@ -42,11 +42,9 @@
Queue::fake();
// Test non-existing user ID
- $job = new \App\Jobs\User\VerifyJob(123);
+ $job = (new \App\Jobs\User\VerifyJob(123))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertTrue($job->hasFailed());
- $this->assertSame("User 123 could not be found in the database.", $job->failureMessage);
+ $job->assertFailedWith("User 123 could not be found in the database.");
// Test existing user
$user = $this->getTestUser('ned@kolab.org');

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 4, 4:03 PM (5 h, 1 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18830293
Default Alt Text
D5169.1775318611.diff (44 KB)

Event Timeline