PredisTests.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use League\Flysystem\Cached\Storage\Predis;
  3. use PHPUnit\Framework\TestCase;
  4. class PredisTests extends TestCase
  5. {
  6. public function testLoadFail()
  7. {
  8. $client = Mockery::mock('Predis\Client');
  9. $command = Mockery::mock('Predis\Command\CommandInterface');
  10. $client->shouldReceive('createCommand')->with('get', ['flysystem'])->once()->andReturn($command);
  11. $client->shouldReceive('executeCommand')->with($command)->andReturn(null);
  12. $cache = new Predis($client);
  13. $cache->load();
  14. $this->assertFalse($cache->isComplete('', false));
  15. }
  16. public function testLoadSuccess()
  17. {
  18. $response = json_encode([[], ['' => true]]);
  19. $client = Mockery::mock('Predis\Client');
  20. $command = Mockery::mock('Predis\Command\CommandInterface');
  21. $client->shouldReceive('createCommand')->with('get', ['flysystem'])->once()->andReturn($command);
  22. $client->shouldReceive('executeCommand')->with($command)->andReturn($response);
  23. $cache = new Predis($client);
  24. $cache->load();
  25. $this->assertTrue($cache->isComplete('', false));
  26. }
  27. public function testSave()
  28. {
  29. $data = json_encode([[], []]);
  30. $client = Mockery::mock('Predis\Client');
  31. $command = Mockery::mock('Predis\Command\CommandInterface');
  32. $client->shouldReceive('createCommand')->with('set', ['flysystem', $data])->once()->andReturn($command);
  33. $client->shouldReceive('executeCommand')->with($command)->once();
  34. $cache = new Predis($client);
  35. $cache->save();
  36. }
  37. public function testSaveWithExpire()
  38. {
  39. $data = json_encode([[], []]);
  40. $client = Mockery::mock('Predis\Client');
  41. $command = Mockery::mock('Predis\Command\CommandInterface');
  42. $client->shouldReceive('createCommand')->with('set', ['flysystem', $data])->once()->andReturn($command);
  43. $client->shouldReceive('executeCommand')->with($command)->once();
  44. $expireCommand = Mockery::mock('Predis\Command\CommandInterface');
  45. $client->shouldReceive('createCommand')->with('expire', ['flysystem', 20])->once()->andReturn($expireCommand);
  46. $client->shouldReceive('executeCommand')->with($expireCommand)->once();
  47. $cache = new Predis($client, 'flysystem', 20);
  48. $cache->save();
  49. }
  50. }