ConfigCacheTest.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Test\Cache;
  11. use Assetic\Cache\ConfigCache;
  12. class ConfigCacheTest extends \PHPUnit_Framework_TestCase
  13. {
  14. private $dir;
  15. private $cache;
  16. protected function setUp()
  17. {
  18. $this->dir = sys_get_temp_dir().'/assetic/tests/config_cache';
  19. $this->cache = new ConfigCache($this->dir);
  20. }
  21. protected function tearDown()
  22. {
  23. foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir, \FilesystemIterator::SKIP_DOTS)) as $file) {
  24. unlink($file->getPathname());
  25. }
  26. }
  27. public function testCache()
  28. {
  29. $this->cache->set('foo', array(1, 2, 3));
  30. $this->assertEquals(array(1, 2, 3), $this->cache->get('foo'), '->get() returns the ->set() value');
  31. }
  32. public function testTimestamp()
  33. {
  34. $this->cache->set('bar', array(4, 5, 6));
  35. $this->assertInternalType('integer', $time = $this->cache->getTimestamp('bar'), '->getTimestamp() returns an integer');
  36. $this->assertNotEmpty($time, '->getTimestamp() returns a non-empty number');
  37. }
  38. public function testInvalidValue()
  39. {
  40. $this->setExpectedException('RuntimeException');
  41. $this->cache->get('_invalid');
  42. }
  43. public function testInvalidTimestamp()
  44. {
  45. $this->setExpectedException('RuntimeException');
  46. $this->cache->getTimestamp('_invalid');
  47. }
  48. public function testHas()
  49. {
  50. $this->cache->set('foo', 'bar');
  51. $this->assertTrue($this->cache->has('foo'));
  52. $this->assertFalse($this->cache->has('_invalid'));
  53. }
  54. }