PhpRedisTests.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use League\Flysystem\Cached\Storage\PhpRedis;
  3. use PHPUnit\Framework\TestCase;
  4. class PhpRedisTests extends TestCase
  5. {
  6. public function testLoadFail()
  7. {
  8. $client = Mockery::mock('Redis');
  9. $client->shouldReceive('get')->with('flysystem')->once()->andReturn(false);
  10. $cache = new PhpRedis($client);
  11. $cache->load();
  12. $this->assertFalse($cache->isComplete('', false));
  13. }
  14. public function testLoadSuccess()
  15. {
  16. $response = json_encode([[], ['' => true]]);
  17. $client = Mockery::mock('Redis');
  18. $client->shouldReceive('get')->with('flysystem')->once()->andReturn($response);
  19. $cache = new PhpRedis($client);
  20. $cache->load();
  21. $this->assertTrue($cache->isComplete('', false));
  22. }
  23. public function testSave()
  24. {
  25. $data = json_encode([[], []]);
  26. $client = Mockery::mock('Redis');
  27. $client->shouldReceive('set')->with('flysystem', $data)->once();
  28. $cache = new PhpRedis($client);
  29. $cache->save();
  30. }
  31. public function testSaveWithExpire()
  32. {
  33. $data = json_encode([[], []]);
  34. $client = Mockery::mock('Redis');
  35. $client->shouldReceive('set')->with('flysystem', $data)->once();
  36. $client->shouldReceive('expire')->with('flysystem', 20)->once();
  37. $cache = new PhpRedis($client, 'flysystem', 20);
  38. $cache->save();
  39. }
  40. }