21 private $eventType = ClearingEventTypes::USER;
26 private $removedEvent;
27 private $addedName =
"<added>";
28 private $addedId = 400;
29 private $removedName =
"<removed>";
30 private $removedId = 399;
33 protected $clearingEventProcessor;
35 protected function setUp() :
void
37 $this->timestamp = time();
40 $this->addedLicense = M::mock(ClearingLicense::class);
41 $this->addedLicense->shouldReceive(
"getShortName")->withNoArgs()->andReturn($this->addedName);
42 $this->addedLicense->shouldReceive(
"getId")->withNoArgs()->andReturn($this->addedId);
44 $this->addedEvent = M::mock(ClearingEvent::class);
45 $this->addedEvent->shouldReceive(
"getLicenseShortName")->withNoArgs()->andReturn($this->addedName);
46 $this->addedEvent->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($this->addedId);
47 $this->addedEvent->shouldReceive(
"getClearingLicense")->withNoArgs()->andReturn($this->addedLicense);
48 $this->addedEvent->shouldReceive(
"getTimeStamp")->withNoArgs()->andReturn($this->timestamp);
49 $this->addedEvent->shouldReceive(
"isRemoved")->withNoArgs()->andReturn(
false);
51 $this->removedLicense = M::mock(ClearingLicense::class);
52 $this->removedLicense->shouldReceive(
"getShortName")->withNoArgs()->andReturn($this->removedName);
53 $this->removedLicense->shouldReceive(
"getId")->withNoArgs()->andReturn($this->removedId);
54 $this->removedEvent = M::mock(ClearingEvent::class);
55 $this->removedEvent->shouldReceive(
"getLicenseShortName")->withNoArgs()->andReturn($this->removedName);
56 $this->removedEvent->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($this->removedId);
57 $this->removedEvent->shouldReceive(
"getClearingLicense")->withNoArgs()->andReturn($this->removedLicense);
58 $this->removedEvent->shouldReceive(
"getTimeStamp")->withNoArgs()->andReturn($this->timestamp);
59 $this->removedEvent->shouldReceive(
"isRemoved")->withNoArgs()->andReturn(
true);
62 protected function tearDown() :
void
72 $license = M::mock(ClearingLicense::class);
75 $events[] = $this->
createEvent($this->timestamp, $license);
77 $eventTimestamp = $this->timestamp-3600;
78 $events[] = $this->
createEvent($eventTimestamp, $license);
90 return new ClearingEvent(1, $this->itemId, $eventTimestamp, $this->userId, $this->groupId, $this->eventType, $clearingLicense);
93 public function testFilterEffectiveEvents()
99 $license1 = M::mock(ClearingLicense::class);
100 $license1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licAId);
101 $events[] = $this->
createEvent($this->timestamp, $license1,
false);
103 $license2 = M::mock(ClearingLicense::class);
104 $license2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licBId);
105 $events[] = $this->
createEvent($this->timestamp+60, $license2,
false);
107 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
109 assertThat($filteredEvents, is(arrayWithSize(2)));
110 assertThat($filteredEvents, hasKeyValuePair($licAId,$events[0]));
111 assertThat($filteredEvents, hasKeyValuePair($licBId,$events[1]));
114 public function testFilterEffectiveEventsIdenticalEventsOverride()
118 $licenseRef1 = M::mock(ClearingLicense::class);
119 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
120 $events[] = $this->
createEvent($this->timestamp, $licenseRef1,
false);
122 $licenseRef2 = M::mock(ClearingLicense::class);
123 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
124 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2,
false);
126 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
128 assertThat($filteredEvents, is(arrayWithSize(1)));
129 assertThat($filteredEvents, hasKeyValuePair($licId,$events[1]));
132 public function testFilterEffectiveEventsOppositeIdenticalEventsOverwrite()
137 $licenseRef1 = M::mock(ClearingLicense::class);
138 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
139 $events[] = $this->
createEvent($this->timestamp, $licenseRef1);
141 $licenseRef2 = M::mock(ClearingLicense::class);
142 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
143 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2);
145 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
147 assertThat($filteredEvents, is(arrayWithSize(1)));
148 assertThat($filteredEvents, hasKeyValuePair($licId,$events[1]));
151 public function testFilterEffectiveEventsOppositeIdenticalEventsOverwriteInOtherOrder()
155 $licenseRef1 = M::mock(ClearingLicense::class);
156 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn(
"fortyTwo");
157 $events[] = $this->
createEvent($this->timestamp, $licenseRef1);
159 $licenseRef2 = M::mock(ClearingLicense::class);
160 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn(
"fortyTwo");
161 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2);
163 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
165 assertThat($filteredEvents, is(arrayWithSize(1)));
166 assertThat($filteredEvents, hasKeyValuePair(
'fortyTwo',$events[1]));
169 public function testFilterEffectiveEventsWithEmptyArray()
171 assertThat($this->clearingEventProcessor->filterEffectiveEvents(array()), is(emptyArray()));
createEvent($eventTimestamp, ClearingLicense $clearingLicense)
Functions to process clearing events.
Contains business rules for FOSSology.