Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #253 from eivydas/invalid-job-content
Browse files Browse the repository at this point in the history
Throw exception on invalid job content
  • Loading branch information
roelvanduijnhoven authored Oct 18, 2022
2 parents 30757da + 5aca920 commit 1c79402
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0",
"ext-json": "*",
"laminas/laminas-eventmanager": "^3.4",
"laminas/laminas-servicemanager": "^3.11",
"laminas/laminas-stdlib": "^3.7.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Queue/AbstractQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public function serializeJob(JobInterface $job): string
$data['content'] = base64_encode($data['content']);
}

return json_encode($data);
return json_encode($data, JSON_THROW_ON_ERROR);
}
}
12 changes: 12 additions & 0 deletions tests/src/Queue/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SlmQueueTest\Queue;

use JsonException;
use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -133,6 +134,17 @@ public function testCorrectlySerializeJobServiceName(): void
static::assertEquals($expected, $actual);
}

public function testInvalidSerializeJobContent(): void
{
$job = new SimpleJob();
$job->setMetadata('__name__', 'SimpleJob');
$job->setContent(chr(128));

$this->expectException(JsonException::class);

$this->queue->serializeJob($job);
}

public function testCanCreateJobWithFQCN(): void
{
$this->jobPluginManager->expects($this->once())
Expand Down

0 comments on commit 1c79402

Please sign in to comment.