123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace Predis\Commands;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- class KeyExpireAtTest extends CommandTestCase
- {
-
- protected function getExpectedCommand()
- {
- return 'Predis\Commands\KeyExpireAt';
- }
-
- protected function getExpectedId()
- {
- return 'EXPIREAT';
- }
-
- public function testFilterArguments()
- {
- $arguments = array('key', 'ttl');
- $expected = array('key', 'ttl');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
-
- public function testParseResponse()
- {
- $command = $this->getCommand();
- $this->assertTrue($command->parseResponse(1));
- $this->assertFalse($command->parseResponse(0));
- }
-
- public function testPrefixKeys()
- {
- $arguments = array('key', 'value');
- $expected = array('prefix:key', 'value');
- $command = $this->getCommandWithArgumentsArray($arguments);
- $command->prefixKeys('prefix:');
- $this->assertSame($expected, $command->getArguments());
- }
-
- public function testReturnsFalseOnNonExistingKeys()
- {
- $redis = $this->getClient();
- $this->assertFalse($redis->expireat('foo', 2));
- }
-
- public function testCanExpireKeys()
- {
- $redis = $this->getClient();
- $now = time();
- $redis->set('foo', 'bar');
- $this->assertTrue($redis->expireat('foo', $now + 1));
- $this->assertLessThanOrEqual(1, $redis->ttl('foo'));
- $this->sleep(2);
- $this->assertFalse($redis->exists('foo'));
- }
-
- public function testDeletesKeysOnPastUnixTime()
- {
- $redis = $this->getClient();
- $now = time();
- $redis->set('foo', 'bar');
- $this->assertTrue($redis->expireat('foo', $now - 100));
- $this->assertFalse($redis->exists('foo'));
- }
- }
|