Skip to content

Commit 08eefaa

Browse files
committed
Add validation for progress
1 parent a867ead commit 08eefaa

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/Model/Table/QueuedJobsTable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ public function validationDefault(Validator $validator): Validator {
172172
->requirePresence('job_task', 'create')
173173
->notEmptyString('job_task');
174174

175+
$validator
176+
->greaterThanOrEqual('progress', 0)
177+
->lessThanOrEqual('progress', 1)
178+
->allowEmpty('progress');
179+
175180
return $validator;
176181
}
177182

tests/TestCase/Model/Table/QueueProcessesTableTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ class QueueProcessesTableTest extends TestCase {
2121
protected $QueueProcesses;
2222

2323
/**
24-
* @var array
24+
* @var array<string>
2525
*/
2626
protected $fixtures = [
2727
'plugin.Queue.QueueProcesses',
28+
'plugin.Queue.QueuedJobs',
2829
];
2930

3031
/**

tests/TestCase/Model/Table/QueuedJobsTableTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QueuedJobsTableTest extends TestCase {
2626
protected $QueuedJobs;
2727

2828
/**
29-
* @var array
29+
* @var array<string>
3030
*/
3131
protected $fixtures = [
3232
'plugin.Queue.QueuedJobs',
@@ -104,6 +104,39 @@ public function testCreateAndCount() {
104104
$this->assertSame(1, $this->QueuedJobs->getLength('Queue.ExceptionExample'));
105105
}
106106

107+
/**
108+
* @return void
109+
*/
110+
public function testMarkJobDone() {
111+
$job = $this->QueuedJobs->createJob('Foo', [
112+
'some' => 'random',
113+
'test' => 'data',
114+
]);
115+
$this->assertTrue($this->QueuedJobs->markJobDone($job));
116+
}
117+
118+
/**
119+
* @return void
120+
*/
121+
public function testMarkJobFailed() {
122+
$job = $this->QueuedJobs->createJob('Foo', [
123+
'some' => 'random',
124+
'test' => 'data',
125+
]);
126+
$this->assertTrue($this->QueuedJobs->markJobFailed($job));
127+
}
128+
129+
/**
130+
* @return void
131+
*/
132+
public function testFlushFailedJobs() {
133+
$this->QueuedJobs->createJob('Foo', [
134+
'some' => 'random',
135+
'test' => 'data',
136+
]);
137+
$this->assertSame(0, $this->QueuedJobs->flushFailedJobs());
138+
}
139+
107140
/**
108141
* Test the basic create and fetch functions.
109142
*

0 commit comments

Comments
 (0)