FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ClearingDecisionBuilderTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2018 Siemens AG
4  Author: Johannes Najjar
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\Data;
10 
15 use Mockery as M;
16 
17 class ClearingDecisionBuilderTest extends \PHPUnit\Framework\TestCase
18 {
20  private $sameUpload = true;
22  private $sameFolder = true;
24  private $clearingEvent;
26  private $clearingId;
28  private $uploadTreeId;
30  private $pfileId;
32  private $userName;
34  private $userId;
36  private $type;
38  private $comment;
40  private $reportinfo;
42  private $acknowledgement;
44  private $scope;
46  private $timeStamp;
47 
49  private $clearingDecisionBuilder;
50 
51  protected function setUp() : void
52  {
53  $this->sameUpload = true;
54  $this->sameFolder = true;
55  $this->clearingEvent = M::mock(ClearingEvent::class);
56  $this->clearingId = 8;
57  $this->uploadTreeId = 9;
58  $this->pfileId = 10;
59  $this->userName = "tester";
60  $this->userId = 11;
61  $this->type = DecisionTypes::TO_BE_DISCUSSED;
62  $this->comment = "Test comment";
63  $this->reportinfo = "Test reportinfo";
64  $this->acknowledgement = "Test acknowledgement";
65  $this->scope = DecisionScopes::ITEM;
66  $this->timeStamp = mktime(11, 14, 15, 7, 28, 2012);
67 
68  $this->clearingDecisionBuilder = ClearingDecisionBuilder::create()->setType(DecisionTypes::IDENTIFIED);
69  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
70  }
71 
72  protected function tearDown() : void
73  {
74  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
75  M::close();
76  }
77 
78  public function testSameFolder()
79  {
80  $clearingDec =$this->clearingDecisionBuilder
81  ->setSameFolder($this->sameFolder)
82  ->build();
83  assertThat($clearingDec->getSameFolder(), is($this->sameFolder));
84  }
85 
86  public function testClearingLicenses()
87  {
88  $clearingDec = $this->clearingDecisionBuilder
89  ->setClearingEvents(array($this->clearingEvent))
90  ->build();
91  assertThat($clearingDec->getClearingEvents(), is(arrayContaining($this->clearingEvent)));
92  }
93 
94  public function testPositiveLicenses()
95  {
96  $addedLic = M::mock(LicenseRef::class);
97 
98  $addedClearingLic = M::mock(ClearingLicense::class);
99  $addedClearingLic->shouldReceive('isRemoved')->withNoArgs()->andReturn(false);
100  $addedClearingLic->shouldReceive('getLicenseRef')->withNoArgs()->andReturn($addedLic);
101 
102  $removedClearingLic = M::mock(ClearingLicense::class);
103  $removedClearingLic->shouldReceive('isRemoved')->andReturn(true);
104 
105  $removedClearingEvent = M::mock(ClearingEvent::class);
106 
107  $this->clearingEvent->shouldReceive('getClearingLicense')->andReturn($addedClearingLic);
108  $removedClearingEvent->shouldReceive('getClearingLicense')->andReturn($removedClearingLic);
109 
110  $clearingDec = $this->clearingDecisionBuilder
111  ->setClearingEvents(array($this->clearingEvent, $removedClearingEvent))
112  ->build();
113  assertThat($clearingDec->getPositiveLicenses(), is(arrayContaining($addedLic)));
114  }
115 
116  public function testClearingId()
117  {
118  $clearingDec = $this->clearingDecisionBuilder
119  ->setClearingId($this->clearingId)
120  ->build();
121  assertThat($clearingDec->getClearingId(), is($this->clearingId));
122  }
123 
124  public function testUploadTreeId()
125  {
126  $clearingDec = $this->clearingDecisionBuilder
127  ->setUploadTreeId($this->uploadTreeId)
128  ->build();
129  assertThat($clearingDec->getUploadTreeId(), is($this->uploadTreeId));
130  }
131 
132  public function testPfileId()
133  {
134  $clearingDec = $this->clearingDecisionBuilder
135  ->setPfileId($this->pfileId)
136  ->build();
137  assertThat($clearingDec->getPfileId(), is($this->pfileId));
138  }
139 
140  public function testUserName()
141  {
142  $clearingDec = $this->clearingDecisionBuilder
143  ->setUserName($this->userName)
144  ->build();
145  assertThat($clearingDec->getUserName(), is($this->userName));
146  }
147 
148  public function testUserId()
149  {
150  $clearingDec = $this->clearingDecisionBuilder
151  ->setUserId($this->userId)
152  ->build();
153  assertThat($clearingDec->getUserId(), is($this->userId));
154  }
155 
156  public function testType()
157  {
158  $clearingDec = $this->clearingDecisionBuilder
159  ->setType($this->type)
160  ->build();
161  assertThat($clearingDec->getType(), is($this->type));
162  }
163 
164  public function testDateAdded()
165  {
166  $clearingDec = $this->clearingDecisionBuilder
167  ->setTimeStamp($this->timeStamp)
168  ->build();
169  assertThat($clearingDec->getTimeStamp(), is($this->timeStamp));
170  }
171 }