diff options
author | xue <> | 2006-12-03 22:57:44 +0000 |
---|---|---|
committer | xue <> | 2006-12-03 22:57:44 +0000 |
commit | f76f11a2cb228b4161bd84d9856c148cb49f1bd7 (patch) | |
tree | 306e9ae7062484b22d1601337bb5cf3026d3df4e /tests/unit | |
parent | 503cdec992e78bf4180fa720800b9d3a3bc551e2 (diff) |
added cache dependency classes.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/Caching/TDirectoryCacheDependencyTest.php | 84 | ||||
-rw-r--r-- | tests/unit/Caching/TFileCacheDependencyTest.php | 60 |
2 files changed, 144 insertions, 0 deletions
diff --git a/tests/unit/Caching/TDirectoryCacheDependencyTest.php b/tests/unit/Caching/TDirectoryCacheDependencyTest.php new file mode 100644 index 00000000..786720da --- /dev/null +++ b/tests/unit/Caching/TDirectoryCacheDependencyTest.php @@ -0,0 +1,84 @@ +<?php + +require_once(dirname(__FILE__).'/../phpunit2.php'); + +/** + * @package System.Caching + */ +class TDirectoryCacheDependencyTest extends PHPUnit2_Framework_TestCase +{ + public function setUp() + { + } + + public function tearDown() + { + } + + public function testDirectoryName() + { + $directory=realpath(dirname(__FILE__).'/temp'); + $dependency=new TDirectoryCacheDependency(dirname(__FILE__).'/temp'); + $this->assertEquals($dependency->getDirectory(),$directory); + + try + { + $dependency=new TDirectoryCacheDependency(dirname(__FILE__).'/temp2'); + $this->fail("Expected exception is not raised"); + } + catch(TInvalidDataValueException $e) + { + } + } + + public function testRecursiveCheck() + { + $directory=realpath(dirname(__FILE__).'/temp'); + $dependency=new TDirectoryCacheDependency(dirname(__FILE__).'/temp'); + $this->assertTrue($dependency->getRecursiveCheck()); + $dependency->setRecursiveCheck(false); + $this->assertFalse($dependency->getRecursiveCheck()); + } + + public function testRecursiveLevel() + { + $directory=realpath(dirname(__FILE__).'/temp'); + $dependency=new TDirectoryCacheDependency(dirname(__FILE__).'/temp'); + $this->assertEquals($dependency->getRecursiveLevel(),-1); + $dependency->setRecursiveLevel(5); + $this->assertEquals($dependency->getRecursiveLevel(),5); + } + + public function testHasChanged() + { + $tempFile=dirname(__FILE__).'/temp/foo.txt'; + @unlink($tempFile); + $fw=fopen($tempFile,"w"); + fwrite($fw,"test"); + fclose($fw); + clearstatcache(); + + $dependency=new TDirectoryCacheDependency(dirname($tempFile)); + $str=serialize($dependency); + + // test directory not changed + sleep(2); + $dependency=unserialize($str); + $this->assertFalse($dependency->getHasChanged()); + + // change file + $fw=fopen($tempFile,"w"); + fwrite($fw,"test again"); + fclose($fw); + clearstatcache(); + + // test file changed + sleep(2); + $dependency=unserialize($str); + $this->assertTrue($dependency->getHasChanged()); + + @unlink($tempFile); + } +} + +?>
\ No newline at end of file diff --git a/tests/unit/Caching/TFileCacheDependencyTest.php b/tests/unit/Caching/TFileCacheDependencyTest.php new file mode 100644 index 00000000..6b61aed6 --- /dev/null +++ b/tests/unit/Caching/TFileCacheDependencyTest.php @@ -0,0 +1,60 @@ +<?php + +require_once(dirname(__FILE__).'/../phpunit2.php'); + +/** + * @package System.Caching + */ +class TFileCacheDependencyTest extends PHPUnit2_Framework_TestCase +{ + public function setUp() + { + } + + public function tearDown() + { + } + + public function testFileName() + { + $dependency=new TFileCacheDependency(__FILE__); + $this->assertEquals($dependency->getFileName(),__FILE__); + $this->assertEquals($dependency->getTimestamp(),filemtime(__FILE__)); + + $dependency=new TFileCacheDependency(dirname(__FILE__).'/foo.txt'); + $this->assertFalse($dependency->getTimestamp()); + } + + public function testHasChanged() + { + $tempFile=dirname(__FILE__).'/temp/foo.txt'; + @unlink($tempFile); + $fw=fopen($tempFile,"w"); + fwrite($fw,"test"); + fclose($fw); + clearstatcache(); + + $dependency=new TFileCacheDependency($tempFile); + $str=serialize($dependency); + + // test file not changed + sleep(2); + $dependency=unserialize($str); + $this->assertFalse($dependency->getHasChanged()); + + // change file + $fw=fopen($tempFile,"w"); + fwrite($fw,"test again"); + fclose($fw); + clearstatcache(); + + // test file changed + sleep(2); + $dependency=unserialize($str); + $this->assertTrue($dependency->getHasChanged()); + + @unlink($tempFile); + } +} + +?>
\ No newline at end of file |