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); } }