FOSSology  4.4.0
Open Source License Compliance by Open Source Software
JobTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  SPDX-FileCopyrightText: © 2020 Siemens AG
5  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
6 
7  SPDX-License-Identifier: GPL-2.0-only
8 */
9 
16 
21 use Mockery as M;
22 use PHPUnit\Framework\TestCase;
23 
28 class JobTest extends TestCase
29 {
34  public function testDataFormatV1()
35  {
36  $this->testDataFormat(ApiVersion::V1);
37  }
38 
43  public function testDataFormatV2()
44  {
45  $this->testDataFormat(ApiVersion::V2);
46  }
47 
51  private function testDataFormat($version)
52  {
53  $jobQueue = new JobQueue(44, 'readmeoss', '2024-07-03 20:41:49', '2024-07-03 20:41:50',
54  'Completed', 0, null, [], 0, true, false, true,
55  ['text' => 'ReadMeOss', 'link' => 'http://localhost/repo/api/v1/report/16']
56  );
57 
58  if ($version == ApiVersion::V2){
59  $expectedStatus = [
60  'id' => 22,
61  'name' => 'ojo',
62  'queueDate' => '01-01-2020',
63  'uploadId' => 4,
64  'userName' => "fossy",
65  'groupName' => "fossy",
66  'eta' => 3,
67  'status' => 'Processing',
68  'jobQueue' => $jobQueue->getArray()
69  ];
70 
71  global $container;
72  $userDao = M::mock(UserDao::class);
73  $container = M::mock('ContainerBuilder');
74  $container->shouldReceive('get')->with('dao.user')->andReturn($userDao);
75  $userDao->shouldReceive('getUserName')->with(2)->andReturn('fossy');
76  $userDao->shouldReceive('getGroupNameById')->with(2)->andReturn('fossy');
77  } else {
78  $expectedStatus = [
79  'id' => 22,
80  'name' => 'ojo',
81  'queueDate' => '01-01-2020',
82  'uploadId' => 4,
83  'userId' => 2,
84  'groupId' => 2,
85  'eta' => 3,
86  'status' => 'Processing'
87  ];
88  }
89 
90  $actualJob = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing', $jobQueue->getArray());
91 
92  $this->assertEquals($expectedStatus, $actualJob->getArray($version));
93  }
94 
95  // Getter tests
96  public function testGetId()
97  {
98  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
99  $this->assertEquals(22, $job->getId());
100  }
101 
102  public function testGetName()
103  {
104  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
105  $this->assertEquals('ojo', $job->getName());
106  }
107 
108  public function testGetQueueDate()
109  {
110  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
111  $this->assertEquals('01-01-2020', $job->getQueueDate());
112  }
113 
114  public function testGetUploadId()
115  {
116  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
117  $this->assertEquals(4, $job->getUploadId());
118  }
119 
120  public function testGetUserId()
121  {
122  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
123  $this->assertEquals(2, $job->getUserId());
124  }
125 
126  public function testGetGroupId()
127  {
128  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
129  $this->assertEquals(2, $job->getGroupId());
130  }
131 
132  public function testGetEta()
133  {
134  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
135  $this->assertEquals(3, $job->getEta());
136  }
137 
138  public function testGetStatus()
139  {
140  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
141  $this->assertEquals('Processing', $job->getStatus());
142  }
143 
144  public function testGetJobQueue()
145  {
146  $jobQueue = new JobQueue(44, 'readmeoss', '2024-07-03 20:41:49', '2024-07-03 20:41:50',
147  'Completed', 0, null, [], 0, true, false, true,
148  ['text' => 'ReadMeOss', 'link' => 'http://localhost/repo/api/v1/report/16']
149  );
150  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing', $jobQueue->getArray());
151  $this->assertEquals($jobQueue->getArray(), $job->getJobQueue());
152  }
153 
154  // Setter tests
155  public function testSetName()
156  {
157  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
158  $job->setName('newName');
159  $this->assertEquals('newName', $job->getName());
160  }
161 
162  public function testSetQueueDate()
163  {
164  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
165  $job->setQueueDate('02-02-2020');
166  $this->assertEquals('02-02-2020', $job->getQueueDate());
167  }
168 
169  public function testSetUploadId()
170  {
171  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
172  $job->setUploadId(5);
173  $this->assertEquals(5, $job->getUploadId());
174  }
175 
176  public function testSetUserId()
177  {
178  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
179  $job->setUserId(3);
180  $this->assertEquals(3, $job->getUserId());
181  }
182 
183  public function testSetGroupId()
184  {
185  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
186  $job->setGroupId(4);
187  $this->assertEquals(4, $job->getGroupId());
188  }
189  public function testSetEta()
190  {
191  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
192  $job->setEta(10);
193  $this->assertEquals(10, $job->getEta());
194  }
195 
196  public function testSetStatus()
197  {
198  $job = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing');
199  $job->setStatus('Completed');
200  $this->assertEquals('Completed', $job->getStatus());
201  }
202 }
Model class to hold JobQueue info.
Definition: JobQueue.php:18