Skip to content

Commit

Permalink
Add validation for progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Aug 18, 2022
1 parent a867ead commit 08eefaa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Model/Table/QueuedJobsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public function validationDefault(Validator $validator): Validator {
->requirePresence('job_task', 'create')
->notEmptyString('job_task');

$validator
->greaterThanOrEqual('progress', 0)
->lessThanOrEqual('progress', 1)
->allowEmpty('progress');

return $validator;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Model/Table/QueueProcessesTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class QueueProcessesTableTest extends TestCase {
protected $QueueProcesses;

/**
* @var array
* @var array<string>
*/
protected $fixtures = [
'plugin.Queue.QueueProcesses',
'plugin.Queue.QueuedJobs',
];

/**
Expand Down
35 changes: 34 additions & 1 deletion tests/TestCase/Model/Table/QueuedJobsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QueuedJobsTableTest extends TestCase {
protected $QueuedJobs;

/**
* @var array
* @var array<string>
*/
protected $fixtures = [
'plugin.Queue.QueuedJobs',
Expand Down Expand Up @@ -104,6 +104,39 @@ public function testCreateAndCount() {
$this->assertSame(1, $this->QueuedJobs->getLength('Queue.ExceptionExample'));
}

/**
* @return void
*/
public function testMarkJobDone() {
$job = $this->QueuedJobs->createJob('Foo', [
'some' => 'random',
'test' => 'data',
]);
$this->assertTrue($this->QueuedJobs->markJobDone($job));
}

/**
* @return void
*/
public function testMarkJobFailed() {
$job = $this->QueuedJobs->createJob('Foo', [
'some' => 'random',
'test' => 'data',
]);
$this->assertTrue($this->QueuedJobs->markJobFailed($job));
}

/**
* @return void
*/
public function testFlushFailedJobs() {
$this->QueuedJobs->createJob('Foo', [
'some' => 'random',
'test' => 'data',
]);
$this->assertSame(0, $this->QueuedJobs->flushFailedJobs());
}

/**
* Test the basic create and fetch functions.
*
Expand Down

0 comments on commit 08eefaa

Please sign in to comment.