2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
2018-05-25 07:26:54 +00:00
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
namespace Resque\Test;
|
|
|
|
|
2010-04-18 13:58:43 +00:00
|
|
|
/**
|
2021-02-18 23:23:32 +00:00
|
|
|
* Resque\Stat tests.
|
2010-04-18 13:58:43 +00:00
|
|
|
*
|
2018-05-25 07:26:54 +00:00
|
|
|
* @package Resque/Tests
|
2021-02-18 23:23:32 +00:00
|
|
|
* @author Daniel Mason <daniel@m2.nz>
|
2018-05-25 07:26:54 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
2010-04-18 13:58:43 +00:00
|
|
|
*/
|
2018-05-25 07:26:54 +00:00
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class StatTest extends TestCase
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testStatCanBeIncremented()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Stat::incr('test_incr');
|
|
|
|
\Resque\Stat::incr('test_incr');
|
2018-05-25 07:26:54 +00:00
|
|
|
$this->assertEquals(2, $this->redis->get('resque:stat:test_incr'));
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testStatCanBeIncrementedByX()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Stat::incr('test_incrX', 10);
|
|
|
|
\Resque\Stat::incr('test_incrX', 11);
|
2018-05-25 07:26:54 +00:00
|
|
|
$this->assertEquals(21, $this->redis->get('resque:stat:test_incrX'));
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testStatCanBeDecremented()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Stat::incr('test_decr', 22);
|
|
|
|
\Resque\Stat::decr('test_decr');
|
2018-05-25 07:26:54 +00:00
|
|
|
$this->assertEquals(21, $this->redis->get('resque:stat:test_decr'));
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testStatCanBeDecrementedByX()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Stat::incr('test_decrX', 22);
|
|
|
|
\Resque\Stat::decr('test_decrX', 11);
|
2018-05-25 07:26:54 +00:00
|
|
|
$this->assertEquals(11, $this->redis->get('resque:stat:test_decrX'));
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testGetStatByName()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Stat::incr('test_get', 100);
|
|
|
|
$this->assertEquals(100, \Resque\Stat::get('test_get'));
|
2018-05-25 07:26:54 +00:00
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function testGetUnknownStatReturns0()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
$this->assertEquals(0, \Resque\Stat::get('test_get_unknown'));
|
2018-05-25 07:26:54 +00:00
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|