FOSSology  4.5.1
Open Source License Compliance by Open Source Software
ShowJobTest.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 */
11 
13 
14 use \PHPUnit\Framework\TestCase;
15 
20 class ShowJobTest extends TestCase
21 {
23 
29  public function testConstructor()
30  {
31  $testData = [
32  'jobId' => 123,
33  'jobName' => 'Test Job',
34  'jobQueue' => ['queue1', 'queue2'],
35  'uploadId' => 456
36  ];
37 
38  $showJob = new ShowJob(
39  $testData['jobId'],
40  $testData['jobName'],
41  $testData['jobQueue'],
42  $testData['uploadId']
43  );
44 
45  $this->assertInstanceOf(ShowJob::class, $showJob);
46  }
47 
49 
54  public function testGetJobId()
55  {
56  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
57  $this->assertEquals(123, $showJob->getJobId());
58  }
59 
64  public function testGetJobName()
65  {
66  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
67  $this->assertEquals('Test Job', $showJob->getJobName());
68  }
69 
74  public function testGetJobQueue()
75  {
76  $jobQueue = ['queue1', 'queue2'];
77  $showJob = new ShowJob(123, 'Test Job', $jobQueue, 456);
78  $this->assertEquals($jobQueue, $showJob->getJobQueue());
79  }
80 
85  public function testGetUploadId()
86  {
87  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
88  $this->assertEquals(456, $showJob->getUploadId());
89  }
90 
92 
98  public function testSetJobId()
99  {
100  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
101 
102  // Test with integer
103  $showJob->setJobId(789);
104  $this->assertEquals(789, $showJob->getJobId());
105 
106  // Test with string that should be converted to integer
107  $showJob->setJobId("321");
108  $this->assertEquals(321, $showJob->getJobId());
109  }
110 
115  public function testSetJobName()
116  {
117  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
118  $showJob->setJobName('New Job Name');
119  $this->assertEquals('New Job Name', $showJob->getJobName());
120  }
121 
126  public function testSetJobQueue()
127  {
128  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
129  $newQueue = ['queue3', 'queue4'];
130  $showJob->setJobQueue($newQueue);
131  $this->assertEquals($newQueue, $showJob->getJobQueue());
132  }
133 
139  public function testSetUploadId()
140  {
141  $showJob = new ShowJob(123, 'Test Job', ['queue1'], 456);
142 
143  // Test with integer
144  $showJob->setUploadId(789);
145  $this->assertEquals(789, $showJob->getUploadId());
146 
147  // Test with string that should be converted to integer
148  $showJob->setUploadId("321");
149  $this->assertEquals(321, $showJob->getUploadId());
150  }
151 
156  public function testGetArray()
157  {
158  $testData = [
159  'jobId' => 123,
160  'jobName' => 'Test Job',
161  'jobQueue' => ['queue1', 'queue2'],
162  'uploadId' => 456
163  ];
164 
165  $showJob = new ShowJob(
166  $testData['jobId'],
167  $testData['jobName'],
168  $testData['jobQueue'],
169  $testData['uploadId']
170  );
171 
172  $expectedArray = [
173  'jobId' => $testData['jobId'],
174  'jobName' => $testData['jobName'],
175  'jobQueue' => $testData['jobQueue'],
176  'uploadId' => $testData['uploadId']
177  ];
178 
179  $this->assertEquals($expectedArray, $showJob->getArray());
180  }
181 
186  public function testGetJSON()
187  {
188  $testData = [
189  'jobId' => 123,
190  'jobName' => 'Test Job',
191  'jobQueue' => ['queue1', 'queue2'],
192  'uploadId' => 456
193  ];
194 
195  $showJob = new ShowJob(
196  $testData['jobId'],
197  $testData['jobName'],
198  $testData['jobQueue'],
199  $testData['uploadId']
200  );
201 
202  $expectedArray = [
203  'jobId' => $testData['jobId'],
204  'jobName' => $testData['jobName'],
205  'jobQueue' => $testData['jobQueue'],
206  'uploadId' => $testData['uploadId']
207  ];
208 
209  $this->assertEquals(json_encode($expectedArray), $showJob->getJSON());
210  }
211 }
Model class to hold ShowJob info.
Definition: ShowJob.php:18