FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ClearingResultTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Data\Clearing;
9 
12 use Mockery as M;
13 
14 class ClearingResultTest extends \PHPUnit\Framework\TestCase
15 {
16 
18  private $licenseRef;
20  private $clearingEvent;
22  private $agentClearingEvent1;
24  private $agentClearingEvent2;
26  private $licenseDecisionResult;
27 
28 
29  protected function setUp() : void
30  {
31  $this->licenseRef = M::mock(LicenseRef::class);
32  $this->clearingEvent = M::mock(ClearingEvent::class);
33 
34  $this->agentClearingEvent1 = M::mock(AgentClearingEvent::class);
35  $this->agentClearingEvent2 = M::mock(AgentClearingEvent::class);
36 
37  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
38  }
39 
40  protected function tearDown() : void
41  {
42  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
43  }
44 
45  public function testHasAgentDecisionEventIsTrue()
46  {
47  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
48  assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(true));
49  }
50 
51  public function testHasAgentDecisionEventIsFalse()
52  {
53  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent);
54  assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(false));
55  }
56 
57  public function testHasDecisionEventIsTrue()
58  {
59  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
60  assertThat($this->licenseDecisionResult->hasClearingEvent(), is(true));
61  }
62 
63  public function testHasDecisionEventIsFalse()
64  {
65  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
66  assertThat($this->licenseDecisionResult->hasClearingEvent(), is(false));
67  }
68 
69  public function testGetLicenseRefFromClearingEvent()
70  {
71  $this->clearingEvent->shouldReceive("getLicenseRef")->once()->andReturn($this->licenseRef);
72  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
73  assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
74  }
75 
76  public function testGetLicenseRefFromAgentEvents()
77  {
78  $this->agentClearingEvent1->shouldReceive("getLicenseRef")->once()->andReturn($this->licenseRef);
79  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1, $this->agentClearingEvent2));
80  assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
81  }
82 
83  public function testGetLicenseIdFromClearingEvent()
84  {
85  $licenseId = 123;
86  $this->clearingEvent->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
87  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
88  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
89  }
90 
91 
92  public function testGetLicenseIdFromAgentEvent()
93  {
94  $licenseId = 123;
95  $this->agentClearingEvent1->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
96  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
97  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
98  }
99 
100  public function testGetLicenseShortName()
101  {
102  $licenseShortName = "<shortName>";
103  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
104  $this->clearingEvent->shouldReceive("getLicenseShortName")->once()->andReturn($licenseShortName);
105  assertThat($this->licenseDecisionResult->getLicenseShortName(), is($licenseShortName));
106  }
107 
108  public function testGetLicenseFullName()
109  {
110  $licenseFullName = "<fullName>";
111  $this->clearingEvent->shouldReceive("getLicenseFullName")->once()->andReturn($licenseFullName);
112  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
113  assertThat($this->licenseDecisionResult->getLicenseFullName(), is($licenseFullName));
114  }
115 
116  public function testGetCommentWithClearingEvent()
117  {
118  $comment = "<comment>";
119  $this->clearingEvent->shouldReceive("getComment")->once()->andReturn($comment);
120  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
121  assertThat($this->licenseDecisionResult->getComment(), is($comment));
122  }
123 
124  public function testGetCommentWithoutClearingEvent()
125  {
126  $comment = "";
127  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
128  assertThat($this->licenseDecisionResult->getComment(), is($comment));
129  }
130 
131  public function testGetReportInfoWithClearingEvent()
132  {
133  $reportInfo = "<reportInfo>";
134  $this->clearingEvent->shouldReceive("getReportinfo")->once()->andReturn($reportInfo);
135  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
136  assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
137  }
138 
139 
140  public function testGetAcknowledgementWithClearingEvent()
141  {
142  $acknowledgement = "<acknowledgement>";
143  $this->clearingEvent->shouldReceive("getAcknowledgement")->once()->andReturn($acknowledgement);
144  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
145  assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
146  }
147 
148  public function testGetReportInfoWithoutClearingEvent()
149  {
150  $reportInfo = "";
151  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
152  assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
153  }
154 
155  public function testGetAcknowledgementWithoutClearingEvent()
156  {
157  $acknowledgement = "";
158  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
159  assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
160  }
161 
162  public function testIsRemoved()
163  {
164  $this->clearingEvent->shouldReceive("isRemoved")->once()->andReturn(true);
165  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
166  assertThat($this->licenseDecisionResult->isRemoved(), is(true));
167  }
168 
169  public function testGetTimeStamp()
170  {
171  $ts = time();
172  $this->clearingEvent->shouldReceive("getTimeStamp")->once()->andReturn($ts);
173  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
174  assertThat($this->licenseDecisionResult->getTimeStamp(), is($ts));
175  }
176 
177  public function testEventTypeWithClearingEvent()
178  {
179  $eventType = "<eventType>";
180  $this->clearingEvent->shouldReceive("getEventType")->once()->andReturn($eventType);
181  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
182  assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
183  }
184 
185  public function testEventTypeWithoutClearingEvent()
186  {
187  $eventType = "<eventType>";
188  $this->agentClearingEvent1->shouldReceive("getEventType")->once()->andReturn($eventType);
189  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
190  assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
191  }
192 
193  public function testGetLicenseIdWithClearingEvent()
194  {
195  $licenseId = 123;
196  $this->clearingEvent->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
197  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
198  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
199  }
200 
201  public function testGetLicenseIdWithoutClearingEvent()
202  {
203  $licenseId = 123;
204  $this->agentClearingEvent1->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
205  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
206  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
207  }
208 
209  public function testGetClearingEvent()
210  {
211  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
212  assertThat($this->licenseDecisionResult->getClearingEvent(), is($this->clearingEvent));
213  }
214 
215  public function testGetAgentClearingEvents()
216  {
217  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
218  assertThat($this->licenseDecisionResult->getAgentDecisionEvents(), is(array(
219  $this->agentClearingEvent1, $this->agentClearingEvent2)));
220  }
221 
222  public function testCreateClearingResultCreationFailsOfNoEventsWereFound()
223  {
224  $this->expectException(\Exception::class);
225  $this->expectExceptionMessage("cannot create ClearingEvent without any "
226  . "event contained");
227  new ClearingResult(null);
228  }
229 }
Fossology exception.
Definition: Exception.php:15