FOSSology  4.5.1
Open Source License Compliance by Open Source Software
LicenseStandardCommentTest.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 LicenseStandardCommentTest extends TestCase
23 {
24  private $sampleData;
25 
29  protected function setUp(): void
30  {
31  $this->sampleData = [
32  'id' => 1,
33  'name' => 'Test Comment',
34  'comment' => 'This is a test standard comment',
35  'isEnabled' => true
36  ];
37  }
38 
40 
46  public function testConstructor()
47  {
48  $standardComment = new LicenseStandardComment(
49  $this->sampleData['id'],
50  $this->sampleData['name'],
51  $this->sampleData['comment'],
52  $this->sampleData['isEnabled']
53  );
54  $this->assertInstanceOf(LicenseStandardComment::class, $standardComment);
55  }
56 
58 
63  public function testGetId()
64  {
65  $standardComment = new LicenseStandardComment($this->sampleData['id'], '', '', false);
66  $this->assertEquals($this->sampleData['id'], $standardComment->getId());
67  }
68 
69 
74  public function testGetName()
75  {
76  $standardComment = new LicenseStandardComment(0, $this->sampleData['name'], '', false);
77  $this->assertEquals($this->sampleData['name'], $standardComment->getName());
78  }
79 
80 
85  public function testGetComment()
86  {
87  $standardComment = new LicenseStandardComment(0, '', $this->sampleData['comment'], false);
88  $this->assertEquals($this->sampleData['comment'], $standardComment->getComment());
89  }
90 
91 
96  public function testGetIsEnabled()
97  {
98  $standardComment = new LicenseStandardComment(0, '', '', true);
99  $this->assertTrue($standardComment->getIsEnabled());
100  }
101 
103 
108  public function testSetId()
109  {
110  $standardComment = new LicenseStandardComment(0, '', '', false);
111  $standardComment->setId(2);
112  $this->assertEquals(2, $standardComment->getId());
113  }
114 
119  public function testSetName()
120  {
121  $standardComment = new LicenseStandardComment(0, '', '', false);
122  $standardComment->setName('Updated Name');
123  $this->assertEquals('Updated Name', $standardComment->getName());
124  }
125 
130  public function testSetComment()
131  {
132  $standardComment = new LicenseStandardComment(0, '', '', false);
133  $standardComment->setComment('Updated Comment');
134  $this->assertEquals('Updated Comment', $standardComment->getComment());
135  }
136 
141  public function testSetIsEnabled()
142  {
143  $standardComment = new LicenseStandardComment(0, '', '', false);
144  $standardComment->setIsEnabled(true);
145  $this->assertTrue($standardComment->getIsEnabled());
146  }
147 
152  public function testGetArrayV1()
153  {
154  $standardComment = new LicenseStandardComment(
155  $this->sampleData['id'],
156  $this->sampleData['name'],
157  $this->sampleData['comment'],
158  $this->sampleData['isEnabled']
159  );
160  $expectedArray = [
161  'id' => $this->sampleData['id'],
162  'name' => $this->sampleData['name'],
163  'comment' => $this->sampleData['comment'],
164  'is_enabled' => $this->sampleData['isEnabled']
165  ];
166  $this->assertEquals($expectedArray, $standardComment->getArray(ApiVersion::V1));
167  }
168 
173  public function testGetArrayV2()
174  {
175  $standardComment = new LicenseStandardComment(
176  $this->sampleData['id'],
177  $this->sampleData['name'],
178  $this->sampleData['comment'],
179  $this->sampleData['isEnabled']
180  );
181  $expectedArray = [
182  'id' => $this->sampleData['id'],
183  'name' => $this->sampleData['name'],
184  'comment' => $this->sampleData['comment'],
185  'isEnabled' => $this->sampleData['isEnabled']
186  ];
187  $this->assertEquals($expectedArray, $standardComment->getArray(ApiVersion::V2));
188  }
189 
194  public function testGetJSONV1()
195  {
196  $standardComment = new LicenseStandardComment(
197  $this->sampleData['id'],
198  $this->sampleData['name'],
199  $this->sampleData['comment'],
200  $this->sampleData['isEnabled']
201  );
202  $json = $standardComment->getJSON(ApiVersion::V1);
203  $this->assertIsString($json);
204  $this->assertEquals(json_decode($json, true), $standardComment->getArray(ApiVersion::V1));
205  }
206 
211  public function testGetJSONV2()
212  {
213  $standardComment = new LicenseStandardComment(
214  $this->sampleData['id'],
215  $this->sampleData['name'],
216  $this->sampleData['comment'],
217  $this->sampleData['isEnabled']
218  );
219  $json = $standardComment->getJSON(ApiVersion::V2);
220  $this->assertIsString($json);
221  $this->assertEquals(json_decode($json, true), $standardComment->getArray(ApiVersion::V2));
222  }
223 
228  public function testEmptyValues()
229  {
230  $standardComment = new LicenseStandardComment(0, '', '', false);
231  $this->assertEquals(0, $standardComment->getId());
232  $this->assertEquals('', $standardComment->getName());
233  $this->assertEquals('', $standardComment->getComment());
234  $this->assertFalse($standardComment->getIsEnabled());
235  }
236 }
testGetJSONV2()
Test getting JSON representation for API version 2.
testGetArrayV2()
Test getting an array representation for API version 2.
testGetJSONV1()
Test getting JSON representation for API version 1.
testGetArrayV1()
Test getting an array representation for API version 1.