FOSSology  4.5.1
Open Source License Compliance by Open Source Software
EditedLicenseTest.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 */
6 
13 
16 use PHPUnit\Framework\TestCase;
17 
22 class EditedLicenseTest extends TestCase
23 {
25  private $id = 1;
26  private $shortName = "GPL-2.0";
27  private $count = 5;
28  private $spdxId = "GPL-2.0-only";
29 
31 
37  public function testConstructor()
38  {
39  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
40  $this->assertInstanceOf(EditedLicense::class, $license);
41  }
42 
44 
49  public function testGetId()
50  {
51  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
52  $this->assertEquals($this->id, $license->getId());
53  }
54 
59  public function testGetShortName()
60  {
61  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
62  $this->assertEquals($this->shortName, $license->getShortName());
63  }
64 
69  public function testGetCount()
70  {
71  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
72  $this->assertEquals($this->count, $license->getCount());
73  }
74 
79  public function testGetSpdxId()
80  {
81  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
82  $this->assertEquals($this->spdxId, $license->getSpdxId());
83  }
84 
86 
91  public function testSetId()
92  {
93  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
94  $newId = 2;
95  $license->setId($newId);
96  $this->assertEquals($newId, $license->getId());
97  }
98 
103  public function testSetShortName()
104  {
105  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
106  $newShortName = "MIT";
107  $license->setShortName($newShortName);
108  $this->assertEquals($newShortName, $license->getShortName());
109  }
110 
115  public function testSetCount()
116  {
117  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
118  $newCount = 10;
119  $license->setCount($newCount);
120  $this->assertEquals($newCount, $license->getCount());
121  }
122 
127  public function testSetSpdxId()
128  {
129  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
130  $newSpdxId = "MIT";
131  $license->setSpdxId($newSpdxId);
132  $this->assertEquals($newSpdxId, $license->getSpdxId());
133  }
134 
139  public function testSettersWithNullValues()
140  {
141  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
142 
143  $license->setId(null);
144  $this->assertNull($license->getId());
145 
146  $license->setShortName(null);
147  $this->assertNull($license->getShortName());
148 
149  $license->setCount(null);
150  $this->assertNull($license->getCount());
151 
152  $license->setSpdxId(null);
153  $this->assertNull($license->getSpdxId());
154  }
155 
161  {
162  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
163 
164  $license->setId("100");
165  $this->assertEquals(100, $license->getId());
166 
167  $license->setCount("200");
168  $this->assertEquals(200, $license->getCount());
169 
170  $license->setShortName(123);
171  $this->assertEquals("123", $license->getShortName());
172 
173  $license->setSpdxId(456);
174  $this->assertEquals("456", $license->getSpdxId());
175  }
176 
178 
183  public function testGetArrayV1()
184  {
185  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
186 
187  $expectedArray = [
188  'id' => $this->id,
189  'shortName' => $this->shortName,
190  'count' => $this->count,
191  'spdx_id' => $this->spdxId
192  ];
193 
194  $this->assertEquals($expectedArray, $license->getArray(ApiVersion::V1));
195  }
196 
201  public function testGetArrayV2()
202  {
203  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
204 
205  $expectedArray = [
206  'id' => $this->id,
207  'shortName' => $this->shortName,
208  'count' => $this->count,
209  'spdxId' => $this->spdxId
210  ];
211 
212  $this->assertEquals($expectedArray, $license->getArray(ApiVersion::V2));
213  }
214 
219  public function testGetJsonV1()
220  {
221  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
222 
223  $resultV1 = $license->getJSON(ApiVersion::V1);
224  $this->assertIsString($resultV1);
225  $this->assertJson($resultV1);
226  $this->assertEquals($license->getArray(ApiVersion::V1), json_decode($resultV1, true));
227  }
228 
233  public function testGetJsonV2()
234  {
235  $license = new EditedLicense($this->id, $this->shortName, $this->count, $this->spdxId);
236 
237  $resultV2 = $license->getJSON(ApiVersion::V2);
238  $this->assertIsString($resultV2);
239  $this->assertJson($resultV2);
240  $this->assertEquals($license->getArray(ApiVersion::V2), json_decode($resultV2, true));
241  }
242 }