FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ReuserTest.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 
17 
22 class ReuserTest extends \PHPUnit\Framework\TestCase
23 {
28  public function testReuserConst()
29  {
30  $expectedArray = [
31  "reuse_upload" => 2,
32  "reuse_group" => 'fossy',
33  "reuse_main" => true,
34  "reuse_enhanced" => false,
35  "reuse_copyright" => false,
36  "reuse_report" => false
37  ];
38 
39  $actualReuser = new Reuser(2, 'fossy', true);
40 
41  $this->assertEquals($expectedArray, $actualReuser->getArray());
42  }
43 
49  public function testReuserException()
50  {
51  $this->expectException(\UnexpectedValueException::class);
52  $this->expectExceptionMessage("reuse_upload should be integer");
53  $object = new Reuser('alpha', 2);
54  }
55 
61  public function testSetUsingArrayV1()
62  {
63  $this->testSetUsingArray(ApiVersion::V1);
64  }
65 
71  public function testSetUsingArrayV2()
72  {
73  $this->testSetUsingArray(ApiVersion::V2);
74  }
75 
81  private function testSetUsingArray($version)
82  {
83  if ($version == ApiVersion::V1) {
84  $expectedArray = [
85  "reuse_upload" => 2,
86  "reuse_group" => 'fossy',
87  "reuse_main" => 'true',
88  "reuse_enhanced" => false,
89  "reuse_copyright" => false,
90  "reuse_report" => false
91  ];
92  } else {
93  $expectedArray = [
94  "reuseUpload" => 2,
95  "reuseGroup" => 'fossy',
96  "reuseMain" => 'true',
97  "reuseEnhanced" => false,
98  "reuseCopyright" => false,
99  "reuseReport" => false
100  ];
101  }
102 
103  $actualReuser = new Reuser(1, 'fossy');
104  $actualReuser->setUsingArray($expectedArray, $version);
105 
106  $expectedArray[$version == ApiVersion::V1? "reuse_main" : "reuseMain"] = true;
107  $this->assertEquals($expectedArray, $actualReuser->getArray($version));
108  }
109 
116  {
117  $expectedArray = [
118  "reuse_upload" => 2,
119  "reuse_group" => 'fossy',
120  "reuse_main" => 'true',
121  "reuse_enhanced" => false,
122  "reuse_copyright" => 'true',
123  "reuse_report" => false
124  ];
125 
126  $actualReuser = new Reuser(1, 'fossy');
127  $actualReuser->setUsingArray($expectedArray);
128 
129  $expectedArray["reuse_main"] = true;
130  $expectedArray["reuse_copyright"] = true;
131  $this->assertEquals($expectedArray, $actualReuser->getArray());
132  }
133 
139  public function testSetUsingArrayException()
140  {
141  $expectedArray = [
142  "reuse_upload" => 'alpha',
143  "reuse_group" => 'fossy',
144  "reuse_main" => 'true',
145  "reuse_enhanced" => false
146  ];
147 
148  $this->expectException(\UnexpectedValueException::class);
149  $this->expectExceptionMessage("Reuse upload should be an integer");
150 
151  $actualReuser = new Reuser(1, 'fossy');
152  $actualReuser->setUsingArray($expectedArray);
153  }
154 }
Model to hold info required by Reuser agent.
Definition: Reuser.php:18