mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Clean up the Conf test a bit
This commit is contained in:
parent
9bffb46aa8
commit
ad0f28b8cc
1 changed files with 23 additions and 17 deletions
|
@ -8,32 +8,38 @@ class TestConf extends \PHPUnit\Framework\TestCase {
|
||||||
use TestingHelpers;
|
use TestingHelpers;
|
||||||
|
|
||||||
static $vfs;
|
static $vfs;
|
||||||
|
static $path;
|
||||||
|
|
||||||
static function setUpBeforeClass() {
|
static function setUpBeforeClass() {
|
||||||
$vfs = vfsStream::setup()->url();
|
self::$vfs = vfsStream::setup();
|
||||||
|
self::$path = self::$vfs->url();
|
||||||
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) {
|
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) {
|
||||||
touch($vfs."/".$file);
|
touch(self::$path."/".$file);
|
||||||
}
|
}
|
||||||
chmod($vfs."/confUnreadable", 0000);
|
chmod(self::$path."/confUnreadable", 0000);
|
||||||
$validConf = <<<'VALID_CONFIGURATION_FILE'
|
$validConf = <<<'VALID_CONFIGURATION_FILE'
|
||||||
<?php
|
<?php
|
||||||
return Array(
|
return Array(
|
||||||
"lang" => "xx"
|
"lang" => "xx"
|
||||||
);
|
);
|
||||||
VALID_CONFIGURATION_FILE;
|
VALID_CONFIGURATION_FILE;
|
||||||
file_put_contents($vfs."/confGood",$validConf);
|
file_put_contents(self::$path."/confGood",$validConf);
|
||||||
file_put_contents($vfs."/confNotArray", "<?php return 0;");
|
file_put_contents(self::$path."/confNotArray", '<?php return 0;');
|
||||||
file_put_contents($vfs."/confCorrupt", "<?php return 0");
|
file_put_contents(self::$path."/confCorrupt", '<?php return 0');
|
||||||
file_put_contents($vfs."/confNotPHP", "DEAD BEEF");
|
file_put_contents(self::$path."/confNotPHP", 'DEAD BEEF');
|
||||||
self::$vfs = $vfs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testConstruct() {
|
static function tearDownAfterClass() {
|
||||||
|
self::$path = null;
|
||||||
|
self::$vfs = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructor() {
|
||||||
$this->assertInstanceOf(Conf::class, new Conf());
|
$this->assertInstanceOf(Conf::class, new Conf());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testConstruct
|
* @depends testConstructor
|
||||||
*/
|
*/
|
||||||
function testImportArray() {
|
function testImportArray() {
|
||||||
$arr = ['lang' => "xx"];
|
$arr = ['lang' => "xx"];
|
||||||
|
@ -47,9 +53,9 @@ VALID_CONFIGURATION_FILE;
|
||||||
*/
|
*/
|
||||||
function testImportFile() {
|
function testImportFile() {
|
||||||
$conf = new Conf();
|
$conf = new Conf();
|
||||||
$conf->importFile(self::$vfs."/confGood");
|
$conf->importFile(self::$path."/confGood");
|
||||||
$this->assertEquals("xx", $conf->lang);
|
$this->assertEquals("xx", $conf->lang);
|
||||||
$conf = new Conf(self::$vfs."/confGood");
|
$conf = new Conf(self::$path."/confGood");
|
||||||
$this->assertEquals("xx", $conf->lang);
|
$this->assertEquals("xx", $conf->lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +64,7 @@ VALID_CONFIGURATION_FILE;
|
||||||
*/
|
*/
|
||||||
function testImportFileMissing() {
|
function testImportFileMissing() {
|
||||||
$this->assertException("fileMissing", "Conf");
|
$this->assertException("fileMissing", "Conf");
|
||||||
$conf = new Conf(self::$vfs."/confMissing");
|
$conf = new Conf(self::$path."/confMissing");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +72,7 @@ VALID_CONFIGURATION_FILE;
|
||||||
*/
|
*/
|
||||||
function testImportFileUnreadable() {
|
function testImportFileUnreadable() {
|
||||||
$this->assertException("fileUnreadable", "Conf");
|
$this->assertException("fileUnreadable", "Conf");
|
||||||
$conf = new Conf(self::$vfs."/confUnreadable");
|
$conf = new Conf(self::$path."/confUnreadable");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +80,7 @@ VALID_CONFIGURATION_FILE;
|
||||||
*/
|
*/
|
||||||
function testImportFileNotAnArray() {
|
function testImportFileNotAnArray() {
|
||||||
$this->assertException("fileCorrupt", "Conf");
|
$this->assertException("fileCorrupt", "Conf");
|
||||||
$conf = new Conf(self::$vfs."/confNotArray");
|
$conf = new Conf(self::$path."/confNotArray");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +89,7 @@ VALID_CONFIGURATION_FILE;
|
||||||
function testImportFileNotPHP() {
|
function testImportFileNotPHP() {
|
||||||
$this->assertException("fileCorrupt", "Conf");
|
$this->assertException("fileCorrupt", "Conf");
|
||||||
// this should not print the output of the non-PHP file
|
// this should not print the output of the non-PHP file
|
||||||
$conf = new Conf(self::$vfs."/confNotPHP");
|
$conf = new Conf(self::$path."/confNotPHP");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +98,6 @@ VALID_CONFIGURATION_FILE;
|
||||||
function testImportFileCorrupt() {
|
function testImportFileCorrupt() {
|
||||||
$this->assertException("fileCorrupt", "Conf");
|
$this->assertException("fileCorrupt", "Conf");
|
||||||
// this should not print the output of the non-PHP file
|
// this should not print the output of the non-PHP file
|
||||||
$conf = new Conf(self::$vfs."/confCorrupt");
|
$conf = new Conf(self::$path."/confCorrupt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue