123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace Test;
- use EasySwoole\Redis\Config\RedisConfig;
- use EasySwoole\Redis\Redis;
- use PHPUnit\Framework\TestCase;
- class OtherTest extends TestCase
- {
-
- protected $redis;
-
- protected $redisPHPSerialize;
-
- protected $redisJsonSerialize;
- protected function setUp() :void
- {
- parent::setUp();
- $this->redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- $this->redisPHPSerialize = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH,
- 'serialize' => RedisConfig::SERIALIZE_PHP
- ]));
- $this->redisJsonSerialize = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH,
- 'serialize' => RedisConfig::SERIALIZE_JSON
- ]));
- $this->redis->connect();
- $this->redisPHPSerialize->connect();
- $this->redisJsonSerialize->connect();
- }
-
- function testPHPSerialize($data)
- {
- $key = 'test';
-
-
- $this->redis->set($key, serialize($data));
-
- $redisData = $this->redisPHPSerialize->get($key);
- $this->assertEquals($redisData, $data);
- }
-
- function testJSONSerialize($data)
- {
- $key = 'test';
-
-
- $this->redis->set($key, json_encode($data));
-
- $redisData = $this->redisJsonSerialize->get($key);
- $this->assertEquals($redisData, $data);
- }
- public function phpSerializeData()
- {
- $class1 = new \stdClass();
- $class1->a = 1;
- $class1->b = 2;
- $class2 = new \stdClass();
- $class2->a = '';
- $class3 = new \stdClass();
- $class3->a = [];
- return [
- [1],
- ['1'],
- [' '],
- [0],
- [null],
- [$class1],
- [$class2],
- [$class3],
- [''],
- [['name' => 'xsk']],
- [[]]
- ];
- }
- public function jsonSerializeData()
- {
- return [
- [1],
- ['1'],
- [' '],
- [0],
- [''],
- [['name' => 'xsk']],
- [[]]
- ];
- }
- }
|