1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Clean up tests a little

This commit is contained in:
J. King 2017-02-08 16:59:16 -05:00
parent bc6ee434e5
commit 3a9753fd22
2 changed files with 36 additions and 32 deletions

View file

@ -11,22 +11,17 @@ class TestConf extends \PHPUnit\Framework\TestCase {
static $path;
static function setUpBeforeClass() {
self::$vfs = vfsStream::setup();
self::$vfs = vfsStream::setup("root", null, [
'confGood' => '<?php return Array("lang" => "xx");',
'confNotArray' => '<?php return 0;',
'confCorrupt' => '<?php return 0',
'confNotPHP' => 'DEAD BEEF',
'confEmpty' => '',
'confUnreadable' => '',
]);
self::$path = self::$vfs->url();
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) {
touch(self::$path."/".$file);
}
// set up a file without read access
chmod(self::$path."/confUnreadable", 0000);
$validConf = <<<'VALID_CONFIGURATION_FILE'
<?php
return Array(
"lang" => "xx"
);
VALID_CONFIGURATION_FILE;
file_put_contents(self::$path."/confGood",$validConf);
file_put_contents(self::$path."/confNotArray", '<?php return 0;');
file_put_contents(self::$path."/confCorrupt", '<?php return 0');
file_put_contents(self::$path."/confNotPHP", 'DEAD BEEF');
}
static function tearDownAfterClass() {
@ -69,6 +64,14 @@ VALID_CONFIGURATION_FILE;
/**
* @depends testImportFile
*/
function testImportFileEmpty() {
$this->assertException("fileCorrupt", "Conf");
$conf = new Conf(self::$path."/confEmpty");
}
/**
* @depends testImportFile
*/
function testImportFileUnreadable() {
$this->assertException("fileUnreadable", "Conf");

View file

@ -9,8 +9,11 @@ class TestLang extends \PHPUnit\Framework\TestCase {
static $vfs;
static $path;
static $files;
const FILES = [
static function setUpBeforeClass() {
Lang\Exception::$test = true;
self::$files = [
'en.php' => '<?php return ["Test.presentText" => "and the Philosopher\'s Stone"];',
'en-ca.php' => '<?php return [];',
'en-us.php' => '<?php return ["Test.presentText" => "and the Sorcerer\'s Stone"];',
@ -25,10 +28,7 @@ class TestLang extends \PHPUnit\Framework\TestCase {
// unreadable file
'ru.php' => '',
];
static function setUpBeforeClass() {
Lang\Exception::$test = true;
self::$vfs = vfsStream::setup("langtest", 0777, self::FILES);
self::$vfs = vfsStream::setup("langtest", 0777, self::$files);
self::$path = self::$vfs->url();
// set up a file without read access
chmod(self::$path."/ru.php", 0000);
@ -38,9 +38,10 @@ class TestLang extends \PHPUnit\Framework\TestCase {
Lang\Exception::$test = false;
self::$path = null;
self::$vfs = null;
self::$files = null;
}
function testList() {
$this->assertEquals(sizeof(self::FILES), sizeof(Lang::list("en", "vfs://langtest/")));
$this->assertEquals(sizeof(self::$files), sizeof(Lang::list("en", "vfs://langtest/")));
}
}