StashTest.php 1.4 KB

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