FOSSology  4.5.1
Open Source License Compliance by Open Source Software
FileLicensesTest.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 
17 use PHPUnit\Framework\TestCase;
18 
23 class FileLicensesTest extends TestCase
24 {
26  private $filePath = "/path/to/file.txt";
27  private $findings;
28  private $clearingStatus = "identified";
29 
33  protected function setUp(): void
34  {
35  parent::setUp();
36  $this->findings = $this->createMock(Findings::class);
37  $this->findings->method('getArray')->willReturn(['mock' => 'findings']);
38  }
39 
41 
47  public function testConstructor()
48  {
49  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
50  $this->assertInstanceOf(FileLicenses::class, $fileLicenses);
51  }
52 
54 
59  public function testGetFilePath()
60  {
61  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
62  $this->assertEquals($this->filePath, $fileLicenses->getFilePath());
63  }
64 
69  public function testGetFindings()
70  {
71  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
72  $this->assertEquals($this->findings, $fileLicenses->getFindings());
73  }
74 
79  public function testGetClearingStatus()
80  {
81  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
82  $this->assertEquals($this->clearingStatus, $fileLicenses->getClearingStatus());
83  }
84 
86 
91  public function testSetFilePath()
92  {
93  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
94  $newPath = "/new/path/file.php";
95  $fileLicenses->setFilePath($newPath);
96  $this->assertEquals($newPath, $fileLicenses->getFilePath());
97  }
98 
103  public function testSetFindings()
104  {
105  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
106  $newFindings = $this->createMock(Findings::class);
107  $fileLicenses->setFindings($newFindings);
108  $this->assertEquals($newFindings, $fileLicenses->getFindings());
109  }
110 
115  public function testSetClearingStatus()
116  {
117  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
118  $newStatus = "cleared";
119  $fileLicenses->setClearingStatus($newStatus);
120  $this->assertEquals($newStatus, $fileLicenses->getClearingStatus());
121  }
122 
127  public function testSettersWithNullValues()
128  {
129  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
130 
131  $fileLicenses->setFilePath(null);
132  $this->assertNull($fileLicenses->getFilePath());
133 
134  $fileLicenses->setFindings(null);
135  $this->assertNull($fileLicenses->getFindings());
136 
137  $fileLicenses->setClearingStatus(null);
138  $this->assertNull($fileLicenses->getClearingStatus());
139  }
140 
145  public function testSetterMethodChaining()
146  {
147  $fileLicenses = new FileLicenses();
148 
149  $result = $fileLicenses->setFilePath($this->filePath)
150  ->setFindings($this->findings)
151  ->setClearingStatus($this->clearingStatus);
152 
153  $this->assertInstanceOf(FileLicenses::class, $result);
154  $this->assertEquals($this->filePath, $fileLicenses->getFilePath());
155  $this->assertEquals($this->findings, $fileLicenses->getFindings());
156  $this->assertEquals($this->clearingStatus, $fileLicenses->getClearingStatus());
157  }
158 
163  public function testGetArrayV1()
164  {
165  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
166 
167  $expectedArray = [
168  'filePath' => $this->filePath,
169  'findings' => ['mock' => 'findings'],
170  'clearing_status' => $this->clearingStatus
171  ];
172 
173  $this->assertEquals($expectedArray, $fileLicenses->getArray(ApiVersion::V1));
174  }
175 
180  public function testGetArrayV2()
181  {
182  $fileLicenses = new FileLicenses($this->filePath, $this->findings, $this->clearingStatus);
183 
184  $expectedArray = [
185  'filePath' => $this->filePath,
186  'findings' => ['mock' => 'findings'],
187  'clearingStatus' => $this->clearingStatus
188  ];
189 
190  $this->assertEquals($expectedArray, $fileLicenses->getArray(ApiVersion::V2));
191  }
192 }
Model holding information about license findings and conclusions.
Definition: Findings.php:18