FOSSology  4.5.1
Open Source License Compliance by Open Source Software
JobQueueTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2025 Harshit Gandhi <gandhiharshit716@gmail.com>
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
13 
15 use PHPUnit\Framework\TestCase;
16 
21 class JobQueueTest extends TestCase
22 {
23  private $jobQueue;
24 
25  protected function setUp(): void
26  {
27  $this->jobQueue = new JobQueue(
28  123,
29  "monkbulk",
30  "2024-02-16 10:00:00",
31  "2024-02-16 10:30:00",
32  "Completed",
33  500,
34  "/srv/fossology/logs/123.log",
35  [1, 2, 3],
36  16.67,
37  true,
38  false,
39  true,
40  ["text" => "Download Report", "link" => "/download/report/123"]
41  );
42  }
43 
45 
51  public function testConstructor()
52  {
53  $this->assertInstanceOf(JobQueue::class, $this->jobQueue);
54  }
55 
57 
62  public function testGetJobQueueId()
63  {
64  $this->assertEquals(123, $this->jobQueue->getJobQueueId());
65  }
66 
71  public function testGetJobQueueType()
72  {
73  $this->assertEquals("monkbulk", $this->jobQueue->getJobQueueType());
74  }
75 
80  public function testGetStartTime()
81  {
82  $this->assertEquals("2024-02-16 10:00:00", $this->jobQueue->getStartTime());
83  }
84 
89  public function testGetEndTime()
90  {
91  $this->assertEquals("2024-02-16 10:30:00", $this->jobQueue->getEndTime());
92  }
93 
98  public function testGetStatus()
99  {
100  $this->assertEquals("Completed", $this->jobQueue->getStatus());
101  }
102 
107  public function testGetItemsProcessed()
108  {
109  $this->assertEquals(500, $this->jobQueue->getItemsProcessed());
110  }
111 
116  public function testGetLog()
117  {
118  $this->assertEquals("/srv/fossology/logs/123.log", $this->jobQueue->getLog());
119  }
120 
125  public function testGetDependencies()
126  {
127  $this->assertEquals([1, 2, 3], $this->jobQueue->getDependencies());
128  }
129 
134  public function testGetItemsPerSec()
135  {
136  $this->assertEquals(16.67, $this->jobQueue->getItemsPerSec());
137  }
138 
143  public function testIsCanDoActions()
144  {
145  $this->assertEquals(true, $this->jobQueue->isCanDoActions());
146  }
147 
152  public function testIsInProgress()
153  {
154  $this->assertEquals(false, $this->jobQueue->isInProgress());
155  }
156 
161  public function testIsReady()
162  {
163  $this->assertEquals(true, $this->jobQueue->isReady());
164  }
165 
170  public function testGetDownload()
171  {
172  $this->assertEquals(["text" => "Download Report", "link" => "/download/report/123"], $this->jobQueue->getDownload());
173  }
174 
176 
181  public function testSetJobQueueId()
182  {
183  $this->jobQueue->setJobQueueId(123);
184  $this->assertEquals(123, $this->jobQueue->getJobQueueId());
185  }
186 
191  public function testSetJobQueueType()
192  {
193  $this->jobQueue->setJobQueueType("monkBulk");
194  $this->assertEquals("monkBulk", $this->jobQueue->getJobQueueType());
195  }
196 
201  public function testSetStartTime()
202  {
203  $this->jobQueue->setStartTime("2024-02-16 10:00:00");
204  $this->assertEquals("2024-02-16 10:00:00", $this->jobQueue->getStartTime());
205  }
206 
211  public function testSetEndTime()
212  {
213  $this->jobQueue->setEndTime("2024-02-16 10:30:00");
214  $this->assertEquals("2024-02-16 10:30:00", $this->jobQueue->getEndTime());
215  }
216 
221  public function testSetStatus()
222  {
223  $this->jobQueue->setStatus("Completed");
224  $this->assertEquals("Completed", $this->jobQueue->getStatus());
225  }
226 
231  public function testSetItemsProcessed()
232  {
233  $this->jobQueue->setItemsProcessed(500);
234  $this->assertEquals(500, $this->jobQueue->getItemsProcessed());
235  }
236 
241  public function testSetItemsPerSec()
242  {
243  $this->jobQueue->setItemsPerSec(16.67);
244  $this->assertEquals(16.67, $this->jobQueue->getItemsPerSec());
245  }
246 
251  public function testSetCanDoActions()
252  {
253  $this->jobQueue->setCanDoActions(true);
254  $this->assertEquals(true, $this->jobQueue->isCanDoActions());
255  }
256 
261  public function testSetIsInProgress()
262  {
263  $this->jobQueue->setCanDoActions(false);
264  $this->assertEquals(false, $this->jobQueue->isInProgress());
265  }
266 
271  public function testSetIsReady()
272  {
273  $this->jobQueue->setIsReady(true);
274  $this->assertEquals(true, $this->jobQueue->isReady());
275  }
276 
281  public function testSetLog()
282  {
283  $this->jobQueue->setLog(null);
284  $this->assertNull($this->jobQueue->getLog());
285  }
286 
291  public function testSetDownload()
292  {
293  $this->jobQueue->setDownload(null);
294  $this->assertNull($this->jobQueue->getDownload());
295  }
296 
301  public function testSetEmptyDependencies()
302  {
303  $this->jobQueue->setDependencies([]);
304  $this->assertEmpty($this->jobQueue->getDependencies());
305  }
306 
308 
313  public function testGetJSON() {
314  $json = $this->jobQueue->getJSON();
315  $this->assertJson($json);
316  $this->assertEquals($this->jobQueue->getArray(), json_decode($json, true));
317  }
318 
320 
325  public function testGetArray()
326  {
327  $expectedArray = [
328  "jobQueueId" => 123,
329  "jobQueueType" => "monkbulk",
330  "startTime" => "2024-02-16 10:00:00",
331  "endTime" => "2024-02-16 10:30:00",
332  "status" => "Completed",
333  "itemsProcessed" => 500,
334  "log" => "/srv/fossology/logs/123.log",
335  "dependencies" => [1, 2, 3],
336  "itemsPerSec" => 16.67,
337  "canDoActions" => true,
338  "isInProgress" => false,
339  "isReady" => true,
340  "download" => ["text" => "Download Report", "link" => "/download/report/123"]
341  ];
342  $this->assertEquals($expectedArray, $this->jobQueue->getArray());
343  }
344 }
Model class to hold JobQueue info.
Definition: JobQueue.php:18