FOSSology  4.5.1
Open Source License Compliance by Open Source Software
ClearingHistoryTest.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 */
12 
14 
15 use PHPUnit\Framework\TestCase;
16 
21 class ClearingHistoryTest extends TestCase
22 {
24 
30  public function testConstructor()
31  {
32  $clearingHistory = new ClearingHistory(
33  "2023-01-01",
34  "testuser",
35  "local",
36  "concluded",
37  ["GPL-2.0", "MIT"],
38  ["Apache-2.0"]
39  );
40  $this->assertInstanceOf(ClearingHistory::class, $clearingHistory);
41  }
42 
47  public function testDataFormat()
48  {
49  $expectedArray = [
50  'date' => "2023-01-01",
51  'username' => "testuser",
52  'scope' => "local",
53  'type' => "concluded",
54  'addedLicenses' => ["GPL-2.0", "MIT"],
55  'removedLicenses' => ["Apache-2.0"]
56  ];
57 
58  $clearingHistory = new ClearingHistory(
59  $expectedArray['date'],
60  $expectedArray['username'],
61  $expectedArray['scope'],
62  $expectedArray['type'],
63  $expectedArray['addedLicenses'],
64  $expectedArray['removedLicenses']
65  );
66 
67  $this->assertEquals($expectedArray, $clearingHistory->getArray());
68  }
69 
71 
76  public function testGetDate()
77  {
78  $date = "2023-01-01";
79  $clearingHistory = new ClearingHistory($date, "testuser", "local", "concluded", [], []);
80  $this->assertEquals($date, $clearingHistory->getDate());
81  }
82 
87  public function testGetUsername()
88  {
89  $username = "testuser";
90  $clearingHistory = new ClearingHistory("2023-01-01", $username, "local", "concluded", [], []);
91  $this->assertEquals($username, $clearingHistory->getUsername());
92  }
93 
98  public function testGetScope()
99  {
100  $scope = "local";
101  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", $scope, "concluded", [], []);
102  $this->assertEquals($scope, $clearingHistory->getScope());
103  }
104 
109  public function testGetType()
110  {
111  $type = "concluded";
112  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", $type, [], []);
113  $this->assertEquals($type, $clearingHistory->getType());
114  }
115 
120  public function testGetAddedLicenses()
121  {
122  $addedLicenses = ["GPL-2.0", "MIT"];
123  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", $addedLicenses, []);
124  $this->assertEquals($addedLicenses, $clearingHistory->getAddedLicenses());
125  }
126 
131  public function testGetRemovedLicenses()
132  {
133  $removedLicenses = ["Apache-2.0"];
134  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], $removedLicenses);
135  $this->assertEquals($removedLicenses, $clearingHistory->getRemovedLicenses());
136  }
137 
139 
144  public function testSetDate()
145  {
146  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
147  $newDate = "2023-02-01";
148  $clearingHistory->setDate($newDate);
149  $this->assertEquals($newDate, $clearingHistory->getDate());
150  }
151 
156  public function testSetUsername()
157  {
158  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
159  $newUsername = "newuser";
160  $clearingHistory->setUsername($newUsername);
161  $this->assertEquals($newUsername, $clearingHistory->getUsername());
162  }
163 
168  public function testSetScope()
169  {
170  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
171  $newScope = "global";
172  $clearingHistory->setScope($newScope);
173  $this->assertEquals($newScope, $clearingHistory->getScope());
174  }
175 
180  public function testSetType()
181  {
182  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
183  $newType = "candidate";
184  $clearingHistory->setType($newType);
185  $this->assertEquals($newType, $clearingHistory->getType());
186  }
187 
192  public function testSetAddedLicenses()
193  {
194  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
195  $newAddedLicenses = ["BSD-3-Clause", "LGPL-2.1"];
196  $clearingHistory->setAddedLicenses($newAddedLicenses);
197  $this->assertEquals($newAddedLicenses, $clearingHistory->getAddedLicenses());
198  }
199 
204  public function testSetRemovedLicenses()
205  {
206  $clearingHistory = new ClearingHistory("2023-01-01", "testuser", "local", "concluded", [], []);
207  $newRemovedLicenses = ["GPL-3.0", "MPL-2.0"];
208  $clearingHistory->setRemovedLicenses($newRemovedLicenses);
209  $this->assertEquals($newRemovedLicenses, $clearingHistory->getRemovedLicenses());
210  }
211 }