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  SPDX-FileCopyrightText: © 2020 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
14 
19 use Mockery as M;
20 
25 class JobTest extends \PHPUnit\Framework\TestCase
26 {
27 
32  public function testDataFormatV1()
33  {
34  $this->testDataFormat(ApiVersion::V1);
35  }
36 
41  public function testDataFormatV2()
42  {
43  $this->testDataFormat(ApiVersion::V2);
44  }
45 
49  private function testDataFormat($version)
50  {
51  $jobQueue = new JobQueue(44, 'readmeoss', '2024-07-03 20:41:49', '2024-07-03 20:41:50',
52  'Completed', 0, null, [], 0, true, false, true,
53  ['text' => 'ReadMeOss', 'link' => 'http://localhost/repo/api/v1/report/16']);
54  if ($version == ApiVersion::V2){
55  $expectedStatus = [
56  'id' => 22,
57  'name' => 'ojo',
58  'queueDate' => '01-01-2020',
59  'uploadId' => 4,
60  'userName' => "fossy",
61  'groupName' => "fossy",
62  'eta' => 3,
63  'status' => 'Processing',
64  'jobQueue' => $jobQueue->getArray()
65  ];
66  global $container;
67  $userDao = M::mock(UserDao::class);
68  $container = M::mock('ContainerBuilder');
69  $container->shouldReceive('get')->withArgs(array(
70  "dao.user"))->andReturn($userDao);
71  $userDao->shouldReceive("getUserName")->with(2)->andReturn("fossy");
72  $userDao->shouldReceive("getGroupNameById")->with(2)->andReturn("fossy");
73  } else {
74  $expectedStatus = [
75  'id' => 22,
76  'name' => 'ojo',
77  'queueDate' => '01-01-2020',
78  'uploadId' => 4,
79  'userId' => 2,
80  'groupId' => 2,
81  'eta' => 3,
82  'status' => 'Processing'
83  ];
84  }
85 
86  $actualJob = new Job(22, 'ojo', '01-01-2020', 4, 2, 2, 3, 'Processing', $jobQueue->getArray());
87 
88  $this->assertEquals($expectedStatus, $actualJob->getArray($version));
89  }
90 }
Model class to hold JobQueue info.
Definition: JobQueue.php:18