Browse Source

Clean up tests a little

microsub
J. King 7 years ago
parent
commit
3a9753fd22
  1. 31
      tests/TestConf.php
  2. 37
      tests/TestLang.php

31
tests/TestConf.php

@ -11,22 +11,17 @@ class TestConf extends \PHPUnit\Framework\TestCase {
static $path;
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();
foreach(["confUnreadable","confGood", "confCorrupt", "confNotArray"] as $file) {
touch(self::$path."/".$file);
}
// set up a file without read access
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() {
@ -69,6 +64,14 @@ VALID_CONFIGURATION_FILE;
/**
* @depends testImportFile
*/
function testImportFileEmpty() {
$this->assertException("fileCorrupt", "Conf");
$conf = new Conf(self::$path."/confEmpty");
}
/**
* @depends testImportFile
*/
function testImportFileUnreadable() {
$this->assertException("fileUnreadable", "Conf");

37
tests/TestLang.php

@ -9,26 +9,26 @@ class TestLang extends \PHPUnit\Framework\TestCase {
static $vfs;
static $path;
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 $files;
static function setUpBeforeClass() {
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();
// set up a file without read access
chmod(self::$path."/ru.php", 0000);
@ -38,9 +38,10 @@ class TestLang extends \PHPUnit\Framework\TestCase {
Lang\Exception::$test = false;
self::$path = null;
self::$vfs = null;
self::$files = null;
}
function testList() {
$this->assertEquals(sizeof(self::FILES), sizeof(Lang::list("en", "vfs://langtest/")));
$this->assertEquals(sizeof(self::$files), sizeof(Lang::list("en", "vfs://langtest/")));
}
}
Loading…
Cancel
Save