FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ClearingDecisionBuilderTest.php
1 <?php
2 /*
3 Copyright (C) 2014-2018, Siemens AG
4 Author: Johannes Najjar
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 namespace Fossology\Lib\Data;
21 
26 use Mockery as M;
27 
28 class ClearingDecisionBuilderTest extends \PHPUnit\Framework\TestCase
29 {
31  private $sameUpload = true;
33  private $sameFolder = true;
35  private $clearingEvent;
37  private $clearingId;
39  private $uploadTreeId;
41  private $pfileId;
43  private $userName;
45  private $userId;
47  private $type;
49  private $comment;
51  private $reportinfo;
53  private $acknowledgement;
55  private $scope;
57  private $timeStamp;
58 
60  private $clearingDecisionBuilder;
61 
62  protected function setUp()
63  {
64  $this->sameUpload = true;
65  $this->sameFolder = true;
66  $this->clearingEvent = M::mock(ClearingEvent::class);
67  $this->clearingId = 8;
68  $this->uploadTreeId = 9;
69  $this->pfileId = 10;
70  $this->userName = "tester";
71  $this->userId = 11;
72  $this->type = DecisionTypes::TO_BE_DISCUSSED;
73  $this->comment = "Test comment";
74  $this->reportinfo = "Test reportinfo";
75  $this->acknowledgement = "Test acknowledgement";
76  $this->scope = DecisionScopes::ITEM;
77  $this->timeStamp = mktime(11, 14, 15, 7, 28, 2012);
78 
79  $this->clearingDecisionBuilder = ClearingDecisionBuilder::create()->setType(DecisionTypes::IDENTIFIED);
80  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
81  }
82 
83  protected function tearDown()
84  {
85  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
86  M::close();
87  }
88 
89  public function testSameFolder()
90  {
91  $clearingDec =$this->clearingDecisionBuilder
92  ->setSameFolder($this->sameFolder)
93  ->build();
94  assertThat($clearingDec->getSameFolder(), is($this->sameFolder));
95  }
96 
97  public function testClearingLicenses()
98  {
99  $clearingDec = $this->clearingDecisionBuilder
100  ->setClearingEvents(array($this->clearingEvent))
101  ->build();
102  assertThat($clearingDec->getClearingEvents(), is(arrayContaining($this->clearingEvent)));
103  }
104 
105  public function testPositiveLicenses()
106  {
107  $addedLic = M::mock(LicenseRef::class);
108 
109  $addedClearingLic = M::mock(ClearingLicense::class);
110  $addedClearingLic->shouldReceive('isRemoved')->withNoArgs()->andReturn(false);
111  $addedClearingLic->shouldReceive('getLicenseRef')->withNoArgs()->andReturn($addedLic);
112 
113  $removedClearingLic = M::mock(ClearingLicense::class);
114  $removedClearingLic->shouldReceive('isRemoved')->andReturn(true);
115 
116  $removedClearingEvent = M::mock(ClearingEvent::class);
117 
118  $this->clearingEvent->shouldReceive('getClearingLicense')->andReturn($addedClearingLic);
119  $removedClearingEvent->shouldReceive('getClearingLicense')->andReturn($removedClearingLic);
120 
121  $clearingDec = $this->clearingDecisionBuilder
122  ->setClearingEvents(array($this->clearingEvent, $removedClearingEvent))
123  ->build();
124  assertThat($clearingDec->getPositiveLicenses(), is(arrayContaining($addedLic)));
125  }
126 
127  public function testClearingId()
128  {
129  $clearingDec = $this->clearingDecisionBuilder
130  ->setClearingId($this->clearingId)
131  ->build();
132  assertThat($clearingDec->getClearingId(), is($this->clearingId));
133  }
134 
135  public function testUploadTreeId()
136  {
137  $clearingDec = $this->clearingDecisionBuilder
138  ->setUploadTreeId($this->uploadTreeId)
139  ->build();
140  assertThat($clearingDec->getUploadTreeId(), is($this->uploadTreeId));
141  }
142 
143  public function testPfileId()
144  {
145  $clearingDec = $this->clearingDecisionBuilder
146  ->setPfileId($this->pfileId)
147  ->build();
148  assertThat($clearingDec->getPfileId(), is($this->pfileId));
149  }
150 
151  public function testUserName()
152  {
153  $clearingDec = $this->clearingDecisionBuilder
154  ->setUserName($this->userName)
155  ->build();
156  assertThat($clearingDec->getUserName(), is($this->userName));
157  }
158 
159  public function testUserId()
160  {
161  $clearingDec = $this->clearingDecisionBuilder
162  ->setUserId($this->userId)
163  ->build();
164  assertThat($clearingDec->getUserId(), is($this->userId));
165  }
166 
167  public function testType()
168  {
169  $clearingDec = $this->clearingDecisionBuilder
170  ->setType($this->type)
171  ->build();
172  assertThat($clearingDec->getType(), is($this->type));
173  }
174 
175  public function testDateAdded()
176  {
177  $clearingDec = $this->clearingDecisionBuilder
178  ->setTimeStamp($this->timeStamp)
179  ->build();
180  assertThat($clearingDec->getTimeStamp(), is($this->timeStamp));
181  }
182 }