/** * @dataProvider testSerializeProvider * @param $tags * @param $timestamp * @param $type * @param $target */ public function testUnserialize($tags, $timestamp, $type, $target) { $timePoint = new TimePoint($tags, $timestamp, $type, $target); $timePointUnserialized = new TimePoint(); $data = $timePoint->serialize(); $timePointUnserialized->unserialize($data); $this->assertEquals($timePointUnserialized->getTimestamp(), $timePoint->getTimestamp()); $this->assertEquals($timePointUnserialized->getTarget(), $timePoint->getTarget()); $this->assertEquals($timePointUnserialized->getTags(), $timePoint->getTags()); $this->assertEquals($timePointUnserialized->getType(), $timePoint->getType()); }
/** * Computes the duration between two TimePoint * @param TimePoint $start * @param TimePoint $end * @return float * @throws InconsistentRangeException */ protected function getRangeDuration($start, $end) { // the two TimePoint must have the same target to be consistent if ($start->getTarget() != $end->getTarget()) { throw new InconsistentRangeException('A time range must be defined by two TimePoint with the same target'); } // the two TimePoint must be correctly ordered $rangeDuration = $end->getTimestamp() - $start->getTimestamp(); if ($rangeDuration < 0) { throw new InconsistentRangeException('A START TimePoint cannot take place after the END!'); } return $rangeDuration; }