-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from YunYinORG/develop
优化配置,添加日志和文件存储单元测试,php5.3断言屏蔽
- Loading branch information
Showing
9 changed files
with
149 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
namespace tests\library\Storage; | ||
|
||
use \Storage\File as File; | ||
use \Yaf_Application as Application; | ||
use \PHPUnit_Framework_TestCase as TestCase; | ||
|
||
class FileTest extends TestCase | ||
{ | ||
const TEST_STRING='yyf file storage test'; | ||
protected static $env; | ||
protected static $dir; | ||
protected static $file; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
static::$dir=APP_PATH.DIRECTORY_SEPARATOR.'runtime'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR; | ||
static::$file=new File(static::$dir); | ||
static::$env= Application::app()->environ(); | ||
} | ||
|
||
/** | ||
* @requires OS Linux | ||
*/ | ||
public function testDirMode() | ||
{ | ||
$mode=('dev'===static::$env)?File::$mode:0700; | ||
clearstatcache(); | ||
$this->assertSame(fileperms(static::$dir)&$mode, $mode); | ||
} | ||
|
||
public function testSet() | ||
{ | ||
$name=uniqid('test_set', true); | ||
static::$file->set($name, FileTest::TEST_STRING); | ||
$filename=static::$dir.$name.'.php'; | ||
$this->assertFileExists($filename); | ||
clearstatcache(); | ||
$this->assertSame(fileperms($filename)&File::$mode, File::$mode); | ||
$this->assertStringEqualsFile($filename, FileTest::TEST_STRING); | ||
return $name; | ||
} | ||
|
||
/** | ||
* @depends testSet | ||
*/ | ||
public function testGet($name) | ||
{ | ||
$str=static::$file->get($name); | ||
$this->assertSame($str, FileTest::TEST_STRING); | ||
$this->assertSame(static::$file->get(uniqid('_rand_', true)), null); | ||
} | ||
|
||
/** | ||
* @depends testSet | ||
*/ | ||
public function testDelete($name) | ||
{ | ||
static::$file->delete($name); | ||
$this->assertFileNotExists(static::$dir.$name.'.php'); | ||
$this->assertSame(static::$file->get($name), null); | ||
} | ||
|
||
/** | ||
* @depends testDelete | ||
*/ | ||
public function testFlush() | ||
{ | ||
for ($i=0; $i < 10; $i++) { | ||
static::$file->set('test_'.uniqid(rand(1000, 10000)), rand()); | ||
} | ||
static::$file->flush(); | ||
$this->assertCount(2, scandir(static::$dir)); | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
File::cleanDir(static::$dir); | ||
rmdir(static::$dir); | ||
} | ||
} |