/RedisDataProviderTestInitial.php Secret
Last active
October 17, 2020 17:02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Trovit\B2B\AdClick\Tests\integration\Infrastructure; | |
use PHPUnit\Framework\TestCase; | |
// some other imports | |
class RedisDataProviderTest extends TestCase | |
{ | |
// some fields... | |
/** * @test */ | |
public function data_expire_after_some_time() | |
{ | |
$currentTimestamp = '2019-06-01 10:00:00'; | |
$this->clock->now()->willReturn($currentTimestamp); | |
$dataProvider = new RedisDataProvider( | |
new PhpRedisClient(), | |
$this->clock->reveal(), | |
$this->tts | |
); | |
$data = $dataProvider->registerData($this->keyData, 1); | |
$expectedData = [ | |
'data' => 1, | |
'timestamp' => $currentTimestamp | |
]; | |
$this->assertEquals($expectedData, $data); | |
$this->assertEquals($expectedData, $this->redis->hGetAll($this->key)); | |
sleep(5.0); // <- waiting for the data to expire | |
$this->assertTrue(empty($this->redis->hGetAll($this->key))); | |
} | |
// other tests... | |
public function setUp() | |
{ | |
$this->keyData = 'some data'; | |
$this->key = 'data:' . $this->keyData; | |
$this->tts = 1; | |
$this->clock = $this->prophesize(Clock::class); | |
$this->connectToRedis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment