FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ClearingDecisionFilterTest.php
1 <?php
2 /*
3 Copyright (C) 2014-2015, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
20 
24 use Mockery as M;
25 
26 class ClearingDecisionFilterTest extends \PHPUnit\Framework\TestCase
27 {
28 
30  private $clearingDecisionFilter;
31 
32  protected function setUp()
33  {
34  $this->clearingDecisionFilter = new ClearingDecisionFilter();
35  }
36 
37  protected function tearDown()
38  {
39  M::close();
40  }
41 
42  public function testFilterCurrentClearingDecisions()
43  {
44  $itemId = 543;
45  $pfileId = 432;
46  $decision1 = M::mock(ClearingDecision::class);
47  $decision1->shouldReceive("getType")->atLeast()->once()->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
48  $decision1->shouldReceive("getScope")->atLeast()->once()->withNoArgs()->andReturn(DecisionScopes::REPO);
49  $decision1->shouldReceive("getUploadTreeId")->andReturn($itemId);
50  $decision1->shouldReceive("getPfileId")->andReturn($pfileId);
51  $decision2 = M::mock(ClearingDecision::class);
52  $decision2->shouldReceive("getType")->atLeast()->once()->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
53  $decision2->shouldReceive("getScope")->atLeast()->once()->withNoArgs()->andReturn(DecisionScopes::ITEM);
54  $decision2->shouldReceive("getUploadTreeId")->andReturn($itemId+1);
55  $decision2->shouldReceive("getPfileId")->andReturn($pfileId);
56  $decisionIrrel = M::mock(ClearingDecision::class);
57  $decisionIrrel->shouldReceive("getType")->atLeast()->once()->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
58 
59  $filteredClearingDecisions = $this->clearingDecisionFilter->filterCurrentClearingDecisions(array($decision1, $decisionIrrel, $decision2));
60 
61  assertThat($this->clearingDecisionFilter->getDecisionOf($filteredClearingDecisions, $itemId, $pfileId), is(sameInstance($decision1)));
62  assertThat($this->clearingDecisionFilter->getDecisionOf($filteredClearingDecisions, $itemId+1, $pfileId), is(sameInstance($decision2)));
63  assertThat($this->clearingDecisionFilter->getDecisionOf($filteredClearingDecisions, $itemId+2, $pfileId), is(sameInstance($decision1)));
64  }
65 
66 
72  {
73  $itemId = 543;
74  $pfileId = 432;
75  $decision = M::mock(ClearingDecision::class);
76  $decision->shouldReceive("getType")->atLeast()->once()->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
77  $decision->shouldReceive("getScope")->atLeast()->once()->withNoArgs()->andReturn(12345);
78  $decision->shouldReceive("getUploadTreeId")->andReturn($itemId);
79  $decision->shouldReceive("getPfileId")->andReturn($pfileId);
80 
81  $this->clearingDecisionFilter->filterCurrentClearingDecisions(array($decision));
82  }
83 
84  public function testFilterCurrentReusableClearingDecisions()
85  {
86  $itemId = 543;
87  $itemId2 = 432;
88  $decision1 = M::mock(ClearingDecision::class);
89  $decision1->shouldReceive("getUploadTreeId")->andReturn($itemId);
90  $decision2 = M::mock(ClearingDecision::class);
91  $decision2->shouldReceive("getUploadTreeId")->andReturn($itemId2);
92 
93  $filteredClearingDecisions = $this->clearingDecisionFilter->filterCurrentReusableClearingDecisions(array($decision1, $decision2));
94  $expecedArray = array($itemId => $decision1, $itemId2 => $decision2 );
95 
96  assertThat($filteredClearingDecisions, containsInAnyOrder($expecedArray));
97  }
98 }
Contains business rules for FOSSology.
Various utility functions to filter ClearingDecision.