CacheEngineTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. namespace Cake\Test\TestCase\Cache\Engine;
  4. use Cake\Cache\InvalidArgumentException;
  5. use Cake\TestSuite\TestCase;
  6. use TestApp\Cache\Engine\TestAppCacheEngine;
  7. class CacheEngineTest extends TestCase
  8. {
  9. public function durationProvider(): array
  10. {
  11. return [
  12. [null, 10],
  13. [2, 2],
  14. [new \DateInterval('PT1S'), 1],
  15. [new \DateInterval('P1D'), 86400],
  16. ];
  17. }
  18. /**
  19. * Test duration with null, int and DateInterval multiple format.
  20. *
  21. * @dataProvider durationProvider
  22. */
  23. public function testDuration($ttl, $expected): void
  24. {
  25. $engine = new TestAppCacheEngine();
  26. $engine->setConfig(['duration' => 10]);
  27. $result = $engine->getDuration($ttl);
  28. $this->assertSame($result, $expected);
  29. }
  30. /**
  31. * Test duration value should be \DateInterval, int or null.
  32. */
  33. public function testDurationException(): void
  34. {
  35. $engine = new TestAppCacheEngine();
  36. $this->expectException(InvalidArgumentException::class);
  37. $this->expectExceptionMessage('TTL values must be one of null, int, \DateInterval');
  38. $engine->getDuration('ttl');
  39. }
  40. }