123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace Predis\Command;
- class SetRandomMemberTest extends PredisCommandTestCase
- {
-
- protected function getExpectedCommand()
- {
- return 'Predis\Command\SetRandomMember';
- }
-
- protected function getExpectedId()
- {
- return 'SRANDMEMBER';
- }
-
- public function testFilterArguments()
- {
- $arguments = array('key', 1);
- $expected = array('key', 1);
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
-
- public function testParseResponse()
- {
- $this->assertSame('member', $this->getCommand()->parseResponse('member'));
- }
-
- public function testPrefixKeys()
- {
- $arguments = array('key');
- $expected = array('prefix:key');
- $command = $this->getCommandWithArgumentsArray($arguments);
- $command->prefixKeys('prefix:');
- $this->assertSame($expected, $command->getArguments());
- }
-
- public function testPrefixKeysIgnoredOnEmptyArguments()
- {
- $command = $this->getCommand();
- $command->prefixKeys('prefix:');
- $this->assertSame(array(), $command->getArguments());
- }
-
- public function testReturnsRandomMemberFromSet()
- {
- $redis = $this->getClient();
- $redis->sadd('letters', 'a', 'b');
- $this->assertContains($redis->srandmember('letters'), array('a', 'b'));
- $this->assertContains($redis->srandmember('letters'), array('a', 'b'));
- $this->assertSame(2, $redis->scard('letters'));
- }
-
- public function testReturnsNullOnNonExistingSet()
- {
- $this->assertNull($this->getClient()->srandmember('letters'));
- }
-
- public function testThrowsExceptionOnWrongType()
- {
- $redis = $this->getClient();
- $redis->set('foo', 'bar');
- $redis->srandmember('foo');
- }
- }
|