2017-02-06 00:00:57 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\NewsSync;
|
|
|
|
use \org\bovigo\vfs\vfsStream;
|
|
|
|
|
|
|
|
|
|
|
|
class TestConf extends \PHPUnit\Framework\TestCase {
|
|
|
|
use TestingHelpers;
|
|
|
|
|
|
|
|
static $vfs;
|
2017-02-08 15:00:38 +00:00
|
|
|
static $path;
|
2017-02-06 00:00:57 +00:00
|
|
|
|
|
|
|
static function setUpBeforeClass() {
|
2017-02-08 21:59:16 +00:00
|
|
|
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' => '',
|
|
|
|
]);
|
2017-02-08 15:00:38 +00:00
|
|
|
self::$path = self::$vfs->url();
|
2017-02-08 21:59:16 +00:00
|
|
|
// set up a file without read access
|
2017-02-08 15:00:38 +00:00
|
|
|
chmod(self::$path."/confUnreadable", 0000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function tearDownAfterClass() {
|
|
|
|
self::$path = null;
|
|
|
|
self::$vfs = null;
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:00:38 +00:00
|
|
|
function testConstructor() {
|
2017-02-06 00:00:57 +00:00
|
|
|
$this->assertInstanceOf(Conf::class, new Conf());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-08 15:00:38 +00:00
|
|
|
* @depends testConstructor
|
2017-02-06 00:00:57 +00:00
|
|
|
*/
|
|
|
|
function testImportArray() {
|
|
|
|
$arr = ['lang' => "xx"];
|
|
|
|
$conf = new Conf();
|
|
|
|
$conf->import($arr);
|
|
|
|
$this->assertEquals("xx", $conf->lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportArray
|
|
|
|
*/
|
|
|
|
function testImportFile() {
|
|
|
|
$conf = new Conf();
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf->importFile(self::$path."/confGood");
|
2017-02-06 00:00:57 +00:00
|
|
|
$this->assertEquals("xx", $conf->lang);
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confGood");
|
2017-02-06 00:00:57 +00:00
|
|
|
$this->assertEquals("xx", $conf->lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
|
|
|
*/
|
|
|
|
function testImportFileMissing() {
|
|
|
|
$this->assertException("fileMissing", "Conf");
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confMissing");
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
2017-02-08 21:59:16 +00:00
|
|
|
*/
|
|
|
|
function testImportFileEmpty() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
$conf = new Conf(self::$path."/confEmpty");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
2017-02-06 00:00:57 +00:00
|
|
|
*/
|
|
|
|
function testImportFileUnreadable() {
|
|
|
|
$this->assertException("fileUnreadable", "Conf");
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confUnreadable");
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
|
|
|
*/
|
|
|
|
function testImportFileNotAnArray() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confNotArray");
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
|
|
|
*/
|
|
|
|
function testImportFileNotPHP() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
// this should not print the output of the non-PHP file
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confNotPHP");
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testImportFile
|
|
|
|
*/
|
|
|
|
function testImportFileCorrupt() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
// this should not print the output of the non-PHP file
|
2017-02-08 15:00:38 +00:00
|
|
|
$conf = new Conf(self::$path."/confCorrupt");
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|
|
|
|
}
|