32 private $eventType = ClearingEventTypes::USER;
37 private $removedEvent;
38 private $addedName =
"<added>";
39 private $addedId = 400;
40 private $removedName =
"<removed>";
41 private $removedId = 399;
44 protected $clearingEventProcessor;
46 protected function setUp()
48 $this->timestamp = time();
51 $this->addedLicense = M::mock(ClearingLicense::class);
52 $this->addedLicense->shouldReceive(
"getShortName")->withNoArgs()->andReturn($this->addedName);
53 $this->addedLicense->shouldReceive(
"getId")->withNoArgs()->andReturn($this->addedId);
55 $this->addedEvent = M::mock(ClearingEvent::class);
56 $this->addedEvent->shouldReceive(
"getLicenseShortName")->withNoArgs()->andReturn($this->addedName);
57 $this->addedEvent->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($this->addedId);
58 $this->addedEvent->shouldReceive(
"getClearingLicense")->withNoArgs()->andReturn($this->addedLicense);
59 $this->addedEvent->shouldReceive(
"getTimeStamp")->withNoArgs()->andReturn($this->timestamp);
60 $this->addedEvent->shouldReceive(
"isRemoved")->withNoArgs()->andReturn(
false);
62 $this->removedLicense = M::mock(ClearingLicense::class);
63 $this->removedLicense->shouldReceive(
"getShortName")->withNoArgs()->andReturn($this->removedName);
64 $this->removedLicense->shouldReceive(
"getId")->withNoArgs()->andReturn($this->removedId);
65 $this->removedEvent = M::mock(ClearingEvent::class);
66 $this->removedEvent->shouldReceive(
"getLicenseShortName")->withNoArgs()->andReturn($this->removedName);
67 $this->removedEvent->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($this->removedId);
68 $this->removedEvent->shouldReceive(
"getClearingLicense")->withNoArgs()->andReturn($this->removedLicense);
69 $this->removedEvent->shouldReceive(
"getTimeStamp")->withNoArgs()->andReturn($this->timestamp);
70 $this->removedEvent->shouldReceive(
"isRemoved")->withNoArgs()->andReturn(
true);
73 protected function tearDown()
83 $license = M::mock(ClearingLicense::class);
86 $events[] = $this->
createEvent($this->timestamp, $license);
88 $eventTimestamp = $this->timestamp-3600;
89 $events[] = $this->
createEvent($eventTimestamp, $license);
101 return new ClearingEvent(1, $this->itemId, $eventTimestamp, $this->userId, $this->groupId, $this->eventType, $clearingLicense);
104 public function testFilterEffectiveEvents()
110 $license1 = M::mock(ClearingLicense::class);
111 $license1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licAId);
112 $events[] = $this->
createEvent($this->timestamp, $license1,
false);
114 $license2 = M::mock(ClearingLicense::class);
115 $license2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licBId);
116 $events[] = $this->
createEvent($this->timestamp+60, $license2,
false);
118 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
120 assertThat($filteredEvents, is(arrayWithSize(2)));
121 assertThat($filteredEvents, hasKeyValuePair($licAId,$events[0]));
122 assertThat($filteredEvents, hasKeyValuePair($licBId,$events[1]));
125 public function testFilterEffectiveEventsIdenticalEventsOverride()
129 $licenseRef1 = M::mock(ClearingLicense::class);
130 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
131 $events[] = $this->
createEvent($this->timestamp, $licenseRef1,
false);
133 $licenseRef2 = M::mock(ClearingLicense::class);
134 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
135 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2,
false);
137 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
139 assertThat($filteredEvents, is(arrayWithSize(1)));
140 assertThat($filteredEvents, hasKeyValuePair($licId,$events[1]));
143 public function testFilterEffectiveEventsOppositeIdenticalEventsOverwrite()
148 $licenseRef1 = M::mock(ClearingLicense::class);
149 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
150 $events[] = $this->
createEvent($this->timestamp, $licenseRef1);
152 $licenseRef2 = M::mock(ClearingLicense::class);
153 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
154 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2);
156 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
158 assertThat($filteredEvents, is(arrayWithSize(1)));
159 assertThat($filteredEvents, hasKeyValuePair($licId,$events[1]));
162 public function testFilterEffectiveEventsOppositeIdenticalEventsOverwriteInOtherOrder()
166 $licenseRef1 = M::mock(ClearingLicense::class);
167 $licenseRef1->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn(
"fortyTwo");
168 $events[] = $this->
createEvent($this->timestamp, $licenseRef1);
170 $licenseRef2 = M::mock(ClearingLicense::class);
171 $licenseRef2->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn(
"fortyTwo");
172 $events[] = $this->
createEvent($this->timestamp+60, $licenseRef2);
174 $filteredEvents = $this->clearingEventProcessor->filterEffectiveEvents($events);
176 assertThat($filteredEvents, is(arrayWithSize(1)));
177 assertThat($filteredEvents, hasKeyValuePair(
'fortyTwo',$events[1]));
180 public function testFilterEffectiveEventsWithEmptyArray()
182 assertThat($this->clearingEventProcessor->filterEffectiveEvents(array()), is(emptyArray()));
createEvent($eventTimestamp, ClearingLicense $clearingLicense)
Functions to process clearing events.
Contains business rules for FOSSology.