Skip to content

Commit 47d5f6a

Browse files
committed
Add tests for helper method for marking a created resource
1 parent c7fc5ff commit 47d5f6a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/Queue/ClientDispatchable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function resourceId(): ?string
6565
}
6666

6767
/**
68-
* Set the resource that the job relates to.
68+
* Set the resource that was created by the job.
6969
*
7070
* If a job is creating a new resource, this method can be used to update
7171
* the client job with the created resource. This method does nothing if the
@@ -74,7 +74,7 @@ public function resourceId(): ?string
7474
* @param $resource
7575
* @return void
7676
*/
77-
public function setResource($resource): void
77+
public function didCreate($resource): void
7878
{
7979
if ($this->wasClientDispatched()) {
8080
$this->clientJob->setResource($resource)->save();

tests/lib/Integration/Queue/QueueEventsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Carbon\Carbon;
66
use CloudCreativity\LaravelJsonApi\Queue\ClientJob;
77
use CloudCreativity\LaravelJsonApi\Tests\Integration\TestCase;
8+
use DummyApp\Download;
89

910
class QueueEventsTest extends TestCase
1011
{
@@ -31,6 +32,10 @@ public function testCompletes()
3132
'completed_at' => Carbon::now()->format('Y-m-d H:i:s'),
3233
'failed' => false,
3334
]);
35+
36+
$clientJob = $job->clientJob->refresh();
37+
38+
$this->assertInstanceOf(Download::class, $clientJob->getResource());
3439
}
3540

3641
public function testFails()

tests/lib/Integration/Queue/TestJob.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CloudCreativity\LaravelJsonApi\Tests\Integration\Queue;
44

55
use CloudCreativity\LaravelJsonApi\Queue\ClientDispatchable;
6+
use DummyApp\Download;
67
use Illuminate\Bus\Queueable;
78
use Illuminate\Contracts\Queue\ShouldQueue;
89
use Illuminate\Foundation\Bus\Dispatchable;
@@ -29,12 +30,20 @@ class TestJob implements ShouldQueue
2930
public $tries = 2;
3031

3132
/**
33+
* Execute the job.
34+
*
35+
* @return Download
3236
* @throws \Exception
3337
*/
34-
public function handle(): void
38+
public function handle(): Download
3539
{
3640
if ($this->ex) {
3741
throw new \LogicException('Boom.');
3842
}
43+
44+
$download = factory(Download::class)->create();
45+
$this->didCreate($download);
46+
47+
return $download;
3948
}
4049
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy