Skip to content

Commit d5715db

Browse files
committed
Add test for encrypted jobs
1 parent 1338a0b commit d5715db

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

tests/Support/EncryptedJob.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Tests\Support;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Foundation\Bus\Dispatchable;
9+
use Illuminate\Queue\InteractsWithQueue;
10+
use Illuminate\Queue\SerializesModels;
11+
12+
class EncryptedJob implements ShouldQueue, ShouldBeEncrypted
13+
{
14+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
15+
16+
public function handle()
17+
{
18+
logger('EncryptedJob:success');
19+
}
20+
}

tests/TaskHandlerTest.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55
use Firebase\JWT\ExpiredException;
66
use Google\Cloud\Tasks\V2\RetryConfig;
77
use Google\Protobuf\Duration;
8-
use Illuminate\Database\Eloquent\Model;
9-
use Illuminate\Queue\Events\JobExceptionOccurred;
10-
use Illuminate\Queue\Events\JobFailed;
118
use Illuminate\Queue\Events\JobProcessed;
129
use Illuminate\Queue\Events\JobProcessing;
13-
use Illuminate\Support\Facades\DB;
1410
use Illuminate\Support\Facades\Event;
1511
use Illuminate\Support\Facades\Log;
16-
use Illuminate\Support\Facades\Queue;
1712
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksApi;
1813
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksException;
19-
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksJob;
2014
use Stackkit\LaravelGoogleCloudTasksQueue\LogFake;
2115
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
2216
use Stackkit\LaravelGoogleCloudTasksQueue\StackkitCloudTask;
17+
use Tests\Support\EncryptedJob;
2318
use Tests\Support\FailingJob;
2419
use Tests\Support\SimpleJob;
2520
use UnexpectedValueException;
@@ -272,4 +267,22 @@ public function test_max_attempts_in_combination_with_retry_until()
272267

273268
$this->assertEquals('failed', $task->fresh()->status);
274269
}
270+
271+
/**
272+
* @test
273+
*/
274+
public function it_can_handle_encrypted_jobs()
275+
{
276+
// Arrange
277+
OpenIdVerificator::fake();
278+
Log::swap(new LogFake());
279+
280+
// Act
281+
$job = $this->dispatch(new EncryptedJob());
282+
$job->run();
283+
284+
// Assert
285+
$this->assertEquals('O:26:"Tests\Support\EncryptedJob":0:{}', decrypt($job->payload['data']['command']));
286+
Log::assertLogged('EncryptedJob:success');
287+
}
275288
}

0 commit comments

Comments
 (0)