/** * Registers a provider. * * @param ProviderInterface $provider * @param int|\DateInterval $lifeTime Life time in seconds or a \DateInterval instance */ public function registerProvider(ProviderInterface $provider, $lifeTime = 3600) { if (!$lifeTime instanceof \DateInterval) { $lifeTime = new \DateInterval(sprintf('PT%dS', $lifeTime)); } $this->providers[$provider->getName()] = array('provider' => $provider, 'lifeTime' => $lifeTime); }
public function it_delays_update(Cache $cache, ProviderInterface $provider) { $numberOfCalls = 0; $cache->fetch('test_http://dunglas.fr')->will(function () use($cache, &$numberOfCalls) { if ($numberOfCalls === 0) { $numberOfCalls++; return array(2, new \DateTime('-1 day')); } return array(1312, new \DateTime()); })->shouldBeCalled(); $cache->save('test_http://dunglas.fr', Argument::that(function ($arg) { return count($arg) === 2 && $arg[0] === 1312; }))->shouldBeCalled(); $provider->getName()->willReturn('test')->shouldBeCalled(); $provider->getShares('http://dunglas.fr')->willReturn(1312)->shouldBeCalled(); $this->registerProvider($provider); $this->getShares('test', 'http://dunglas.fr', true)->shouldReturn(2); $this->update(); $this->getShares('test', 'http://dunglas.fr', true)->shouldReturn(1312); $this->getShares('test', 'http://dunglas.fr', true)->shouldReturn(1312); }