123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace Predis\Command\Redis;
- class HINCRBYFLOAT_Test extends PredisCommandTestCase
- {
-
- protected function getExpectedCommand()
- {
- return 'Predis\Command\Redis\HINCRBYFLOAT';
- }
-
- protected function getExpectedId()
- {
- return 'HINCRBYFLOAT';
- }
-
- public function testFilterArguments()
- {
- $arguments = array('key', 'field', 10.5);
- $expected = array('key', 'field', 10.5);
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
-
- public function testParseResponse()
- {
- $this->assertSame(10.5, $this->getCommand()->parseResponse(10.5));
- }
-
- public function testIncrementsValueOfFieldByFloat()
- {
- $redis = $this->getClient();
- $this->assertSame('10.5', $redis->hincrbyfloat('metavars', 'foo', 10.5));
- $redis->hincrbyfloat('metavars', 'hoge', 10.001);
- $this->assertSame('11', $redis->hincrbyfloat('metavars', 'hoge', 0.999));
- $this->assertSame(array('foo' => '10.5', 'hoge' => '11'), $redis->hgetall('metavars'));
- }
-
- public function testDecrementsValueOfFieldByFloat()
- {
- $redis = $this->getClient();
- $this->assertSame('-10.5', $redis->hincrbyfloat('metavars', 'foo', -10.5));
- $redis->hincrbyfloat('metavars', 'hoge', -10.001);
- $this->assertSame('-11', $redis->hincrbyfloat('metavars', 'hoge', -0.999));
- $this->assertSame(array('foo' => '-10.5', 'hoge' => '-11'), $redis->hgetall('metavars'));
- }
-
- public function testThrowsExceptionOnStringField()
- {
- $redis = $this->getClient();
- $redis->hset('metavars', 'foo', 'bar');
- $redis->hincrbyfloat('metavars', 'foo', 10.0);
- }
-
- public function testThrowsExceptionOnWrongType()
- {
- $redis = $this->getClient();
- $redis->set('foo', 'bar');
- $redis->hincrbyfloat('foo', 'bar', 10.5);
- }
- }
|