Psr6CacheTest.php 1.6 KB

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