FOSSology  4.5.1
Open Source License Compliance by Open Source Software
ScannedLicenseTest.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 
14 
15 use PHPUnit\Framework\TestCase;
16 
21 class ScannedLicenseTest extends TestCase
22 {
24 
30  public function testConstructor()
31  {
32  $testData = [
33  'id' => 1,
34  'shortname' => 'GPL-2.0',
35  'occurence' => 5,
36  'unique' => 2,
37  'spdxName' => 'GPL-2.0-only'
38  ];
39 
40  $license = new ScannedLicense(
41  $testData['id'],
42  $testData['shortname'],
43  $testData['occurence'],
44  $testData['unique'],
45  $testData['spdxName']
46  );
47 
48  $this->assertInstanceOf(ScannedLicense::class, $license);
49  }
50 
52 
57  public function testGetId()
58  {
59  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
60  $this->assertEquals(1, $license->getId());
61  }
62 
67  public function testGetShortname()
68  {
69  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
70  $this->assertEquals('GPL-2.0', $license->getShortname());
71  }
72 
77  public function testGetOccurence()
78  {
79  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
80  $this->assertEquals(5, $license->getOccurence());
81  }
82 
87  public function testGetUnique()
88  {
89  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
90  $this->assertEquals(2, $license->getUnique());
91  }
92 
97  public function testGetSpdxName()
98  {
99  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
100  $this->assertEquals('GPL-2.0-only', $license->getSpdxName());
101  }
102 
104 
109  public function testSetId()
110  {
111  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
112  $license->setId(2);
113  $this->assertEquals(2, $license->getId());
114  }
115 
120  public function testSetShortname()
121  {
122  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
123  $license->setShortname('MIT');
124  $this->assertEquals('MIT', $license->getShortname());
125  }
126 
131  public function testSetOccurence()
132  {
133  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
134  $license->setOccurence(10);
135  $this->assertEquals(10, $license->getOccurence());
136  }
137 
142  public function testSetUnique()
143  {
144  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
145  $license->setUnique(4);
146  $this->assertEquals(4, $license->getUnique());
147  }
148 
153  public function testSetSpdxName()
154  {
155  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
156  $license->setSpdxName('MIT');
157  $this->assertEquals('MIT', $license->getSpdxName());
158  }
159 
164  public function testGetArrayV1()
165  {
166  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
167 
168  $expectedArray = [
169  'id' => 1,
170  'shortname' => 'GPL-2.0',
171  'occurence' => 5,
172  'unique' => 2,
173  'spdxName' => 'GPL-2.0-only'
174  ];
175 
176  $this->assertEquals($expectedArray, $license->getArray(ApiVersion::V1));
177  }
178 
183  public function testGetArrayV2()
184  {
185  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
186 
187  $expectedArray = [
188  'id' => 1,
189  'shortName' => 'GPL-2.0',
190  'occurence' => 5,
191  'unique' => 2,
192  'spdxName' => 'GPL-2.0-only'
193  ];
194 
195  $this->assertEquals($expectedArray, $license->getArray(ApiVersion::V2));
196  }
197 
202  public function testGetJSON()
203  {
204  $license = new ScannedLicense(1, 'GPL-2.0', 5, 2, 'GPL-2.0-only');
205 
206  $expectedArrayV1 = [
207  'id' => 1,
208  'shortname' => 'GPL-2.0',
209  'occurence' => 5,
210  'unique' => 2,
211  'spdxName' => 'GPL-2.0-only'
212  ];
213 
214  $expectedArrayV2 = [
215  'id' => 1,
216  'shortName' => 'GPL-2.0',
217  'occurence' => 5,
218  'unique' => 2,
219  'spdxName' => 'GPL-2.0-only'
220  ];
221 
222  $this->assertEquals(json_encode($expectedArrayV1), $license->getJSON(ApiVersion::V1));
223  $this->assertEquals(json_encode($expectedArrayV2), $license->getJSON(ApiVersion::V2));
224  }
225 }