Files
phalapi-pro/tests/base/Domain/Redis_Test.php
2022-03-21 11:16:38 +08:00

144 lines
2.7 KiB
PHP

<?php
/**
* PhalApi_Base\Domain\Redis_Test
*
* 针对 ../src/base/Domain/Redis.php Base\Domain\Redis 类的PHPUnit单元测试
*
* @author: dogstar 20200717
*/
namespace tests\Base\Domain;
use Base\Domain\Redis;
class PhpUnderControl_BaseDomainRedis_Test extends \PHPUnit\Framework\TestCase
{
public $baseDomainRedis;
protected function setUp()
{
parent::setUp();
$this->baseDomainRedis = new \Base\Domain\Redis();
}
protected function tearDown()
{
// 输出本次单元测试所执行的SQL语句
// var_dump(\PhalApi\DI()->tracer->getSqls());
// 输出本次单元测试所涉及的追踪埋点
// var_dump(\PhalApi\DI()->tracer->getStack());
}
/**
* @group testGet
*/
public function testGet()
{
$key = 'unittest';
$this->baseDomainRedis->set($key, '2020');
$rs = $this->baseDomainRedis->get($key);
$this->assertEquals('2020', $rs);
}
/**
* @group testSet
*/
public function testSet()
{
$key = 'testSet_pro';
$value = 'pro';
$expire = null;
$rs = $this->baseDomainRedis->set($key, $value, $expire);
$key = 'testSet_pro_1';
$value = 'pro';
$expire = 0;
$rs = $this->baseDomainRedis->set($key, $value, $expire);
$key = 'testSet_pro_2';
$value = 'pro';
$expire = 10;
$rs = $this->baseDomainRedis->set($key, $value, $expire);
}
/**
* @group testIncr
*/
public function testIncr()
{
$key = 'testIncr_pro';
$rs = $this->baseDomainRedis->incr($key);
}
/**
* @group testIncrBy
*/
public function testIncrBy()
{
$key = 'testIncr_pro';
$value = 10;
$rs = $this->baseDomainRedis->incrBy($key, $value);
$this->assertGreaterThan($value, $this->baseDomainRedis->get($key));
}
/**
* @group testDecr
*/
public function testDecr()
{
$key = 'testDecr_pro';
$rs = $this->baseDomainRedis->decr($key);
}
/**
* @group testDecrBy
*/
public function testDecrBy()
{
$key = 'testDecr';
$value = '10';
$rs = $this->baseDomainRedis->decrBy($key, $value);
$this->assertLessThan(0, $this->baseDomainRedis->get($key));
}
/**
* @group testDel
*/
public function testDel()
{
$key = 'xxxxx_pro';
$rs = $this->baseDomainRedis->del($key);
$this->assertTrue(is_int($rs));
}
/**
* @group testExists
*/
public function testExists()
{
$key = 'hhhhhh';
$rs = $this->baseDomainRedis->exists($key);
$this->assertEquals(0, $rs);
}
}