function it_increments_the_number_of_ticks(RateMeasureStorage $storage, RateMeasure $measure, Rate $rate) { $rate->getTicks()->willReturn(1); $measure->getTime()->willReturn(new \DateTime()); $measure->getRate()->willReturn($rate); $storage->find('id')->willReturn($measure); $storage->save('id', Argument::type(RateMeasure::class))->shouldBeCalled(); $this->tick('id'); }
/** * Create the current rate. * * @param string $identifier * * @return float */ private function computeCurrentRate($identifier) { $measure = $this->getMeasure($identifier); $lastRequest = (double) $measure->getTime()->format('U.u'); $lastRatio = $measure->getRate()->getTicks(); $difference = (microtime(true) - $lastRequest) * 1000; $rate = max(0, $lastRatio - $difference); $rate += 1000 / $this->rate->getTicks(); return $rate; }