FOSSology  4.5.1
Open Source License Compliance by Open Source Software
OneShotTest.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 */
13 
14 use PHPUnit\Framework\TestCase;
15 
20 class OneShotTest extends TestCase
21 {
23 
29  public function testConstructor()
30  {
31  $testData = ["GPL-2.0", "MIT"];
32  $testHighlight = new Highlight(0, 10, "test");
33  $highlights = [$testHighlight];
34 
35  $oneShot = new OneShot($testData, $highlights);
36 
37  $this->assertInstanceOf(OneShot::class, $oneShot);
38  }
39 
41 
46  public function testGetData()
47  {
48  $testData = ["GPL-2.0", "MIT"];
49  $oneShot = new OneShot($testData, []);
50  $this->assertEquals($testData, $oneShot->getData());
51  }
52 
57  public function testGetHighlights()
58  {
59  $testHighlight = new Highlight(0, 10, "test");
60  $highlights = [$testHighlight];
61  $oneShot = new OneShot([], $highlights);
62  $this->assertEquals($highlights, $oneShot->getHighlights());
63  }
64 
66 
71  public function testSetData()
72  {
73  $oneShot = new OneShot([], []);
74  $newData = ["Apache-2.0"];
75  $oneShot->setData($newData);
76  $this->assertEquals($newData, $oneShot->getData());
77  }
78 
83  public function testSetHighlights()
84  {
85  $oneShot = new OneShot([], []);
86  $newHighlight = new Highlight(5, 15, "new test");
87  $newHighlights = [$newHighlight];
88  $oneShot->setHighlights($newHighlights);
89  $this->assertEquals($newHighlights, $oneShot->getHighlights());
90  }
91 
98  public function testGetHighlightsArray()
99  {
100  $highlight1 = new Highlight(0, 10, "test1");
101  $highlight2 = new Highlight(15, 25, "test2");
102  $highlights = [$highlight1, $highlight2];
103 
104  $oneShot = new OneShot([], $highlights);
105 
106  $expectedArray = [
107  $highlight1->getArray(),
108  $highlight2->getArray()
109  ];
110 
111  $this->assertEquals($expectedArray, $oneShot->getHighlightsArray());
112  }
113 
120  public function testGetArray()
121  {
122  $testData = ["GPL-3.0"];
123  $highlight = new Highlight(0, 7, "GPL");
124  $highlights = [$highlight];
125 
126  $oneShot = new OneShot($testData, $highlights);
127 
128  $expectedArray = [
129  'licenses' => $testData,
130  'highlights' => [$highlight->getArray()]
131  ];
132 
133  $this->assertEquals($expectedArray, $oneShot->getArray());
134  }
135 
142  public function testGetArrayCustomDataType()
143  {
144  $testData = "Sample text";
145  $highlight = new Highlight(0, 6, "Sample");
146  $highlights = [$highlight];
147 
148  $oneShot = new OneShot($testData, $highlights);
149 
150  $expectedArray = [
151  'text' => $testData,
152  'highlights' => [$highlight->getArray()]
153  ];
154 
155  $this->assertEquals($expectedArray, $oneShot->getArray('text'));
156  }
157 
164  public function testGetJSON()
165  {
166  $testData = ["MIT"];
167  $highlight = new Highlight(0, 3, "MIT");
168  $highlights = [$highlight];
169 
170  $oneShot = new OneShot($testData, $highlights);
171 
172  $expectedArray = [
173  'licenses' => $testData,
174  'highlights' => [$highlight->getArray()]
175  ];
176 
177  $this->assertEquals(json_encode($expectedArray), $oneShot->getJSON());
178  }
179 }