1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +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 $path;
static function setUpBeforeClass() { 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(); self::$path = self::$vfs->url();
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) { // set up a file without read access
touch(self::$path."/".$file);
}
chmod(self::$path."/confUnreadable", 0000); 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() { static function tearDownAfterClass() {
@ -69,6 +64,14 @@ VALID_CONFIGURATION_FILE;
/** /**
* @depends testImportFile * @depends testImportFile
*/
function testImportFileEmpty() {
$this->assertException("fileCorrupt", "Conf");
$conf = new Conf(self::$path."/confEmpty");
}
/**
* @depends testImportFile
*/ */
function testImportFileUnreadable() { function testImportFileUnreadable() {
$this->assertException("fileUnreadable", "Conf"); $this->assertException("fileUnreadable", "Conf");

View file

@ -9,26 +9,26 @@ class TestLang extends \PHPUnit\Framework\TestCase {
static $vfs; static $vfs;
static $path; static $path;
static $files;
const 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"];',
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
// corrupt files
'it.php' => '<?php return 0;',
'zh.php' => '<?php return 0',
'ko.php' => 'DEAD BEEF',
// empty file
'fr-ca.php' => '',
// unreadable file
'ru.php' => '',
];
static function setUpBeforeClass() { static function setUpBeforeClass() {
Lang\Exception::$test = true; Lang\Exception::$test = true;
self::$vfs = vfsStream::setup("langtest", 0777, self::FILES); 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"];',
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
// corrupt files
'it.php' => '<?php return 0;',
'zh.php' => '<?php return 0',
'ko.php' => 'DEAD BEEF',
// empty file
'fr-ca.php' => '',
// unreadable file
'ru.php' => '',
];
self::$vfs = vfsStream::setup("langtest", 0777, self::$files);
self::$path = self::$vfs->url(); self::$path = self::$vfs->url();
// set up a file without read access // set up a file without read access
chmod(self::$path."/ru.php", 0000); chmod(self::$path."/ru.php", 0000);
@ -38,9 +38,10 @@ class TestLang extends \PHPUnit\Framework\TestCase {
Lang\Exception::$test = false; Lang\Exception::$test = false;
self::$path = null; self::$path = null;
self::$vfs = null; self::$vfs = null;
self::$files = null;
} }
function testList() { function testList() {
$this->assertEquals(sizeof(self::FILES), sizeof(Lang::list("en", "vfs://langtest/"))); $this->assertEquals(sizeof(self::$files), sizeof(Lang::list("en", "vfs://langtest/")));
} }
} }