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

106 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 Test\Tools;
2017-02-06 00:00:57 +00:00
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-09 21:39:13 +00:00
self::$path = self::$vfs->url()."/";
2017-02-08 21:59:16 +00:00
// set up a file without read access
2017-02-09 21:39:13 +00:00
chmod(self::$path."confUnreadable", 0000);
2017-02-08 15:00:38 +00:00
}
static function tearDownAfterClass() {
self::$path = null;
self::$vfs = null;
2017-02-06 00:00:57 +00:00
}
function testLoadDefaultValues() {
2017-02-06 00:00:57 +00:00
$this->assertInstanceOf(Conf::class, new Conf());
}
/**
* @depends testLoadDefaultValues
2017-02-06 00:00:57 +00:00
*/
function testImportFromArray() {
2017-02-06 00:00:57 +00:00
$arr = ['lang' => "xx"];
$conf = new Conf();
$conf->import($arr);
$this->assertEquals("xx", $conf->lang);
}
/**
* @depends testImportFromArray
2017-02-06 00:00:57 +00:00
*/
function testImportFromFile() {
2017-02-06 00:00:57 +00:00
$conf = new Conf();
2017-02-09 21:39:13 +00:00
$conf->importFile(self::$path."confGood");
2017-02-06 00:00:57 +00:00
$this->assertEquals("xx", $conf->lang);
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confGood");
2017-02-06 00:00:57 +00:00
$this->assertEquals("xx", $conf->lang);
}
/**
* @depends testImportFromFile
2017-02-06 00:00:57 +00:00
*/
function testImportFromMissingFile() {
2017-02-06 00:00:57 +00:00
$this->assertException("fileMissing", "Conf");
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confMissing");
2017-02-06 00:00:57 +00:00
}
/**
* @depends testImportFromFile
2017-02-08 21:59:16 +00:00
*/
function testImportFromEmptyFile() {
2017-02-08 21:59:16 +00:00
$this->assertException("fileCorrupt", "Conf");
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confEmpty");
2017-02-08 21:59:16 +00:00
}
/**
* @depends testImportFromFile
2017-02-06 00:00:57 +00:00
*/
function testImportFromFileWithoutReadPermission() {
2017-02-06 00:00:57 +00:00
$this->assertException("fileUnreadable", "Conf");
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confUnreadable");
2017-02-06 00:00:57 +00:00
}
/**
* @depends testImportFromFile
2017-02-06 00:00:57 +00:00
*/
function testImportFromFileWhichIsNotAnArray() {
2017-02-06 00:00:57 +00:00
$this->assertException("fileCorrupt", "Conf");
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confNotArray");
2017-02-06 00:00:57 +00:00
}
/**
* @depends testImportFromFile
2017-02-06 00:00:57 +00:00
*/
function testImportFromFileWhichIsNotPhp() {
2017-02-06 00:00:57 +00:00
$this->assertException("fileCorrupt", "Conf");
// this should not print the output of the non-PHP file
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confNotPHP");
2017-02-06 00:00:57 +00:00
}
/**
* @depends testImportFromFile
2017-02-06 00:00:57 +00:00
*/
function testImportFromCorruptFile() {
2017-02-06 00:00:57 +00:00
$this->assertException("fileCorrupt", "Conf");
2017-02-09 21:39:13 +00:00
$conf = new Conf(self::$path."confCorrupt");
2017-02-06 00:00:57 +00:00
}
}