1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-09 09:22:40 +00:00
Arsse/tests/TestConf.php

104 lines
2.5 KiB
PHP
Raw Normal View History

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 15:00:38 +00:00
self::$vfs = vfsStream::setup();
self::$path = self::$vfs->url();
2017-02-06 00:00:57 +00:00
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) {
2017-02-08 15:00:38 +00:00
touch(self::$path."/".$file);
2017-02-06 00:00:57 +00:00
}
2017-02-08 15:00:38 +00:00
chmod(self::$path."/confUnreadable", 0000);
$validConf = <<<'VALID_CONFIGURATION_FILE'
2017-02-06 00:00:57 +00:00
<?php
return Array(
"lang" => "xx"
);
VALID_CONFIGURATION_FILE;
2017-02-08 15:00:38 +00:00
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() {
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
*/
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
}
}