From 3a9753fd22d6a46c62eee0e430a859e5c75e1f77 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 8 Feb 2017 16:59:16 -0500 Subject: [PATCH] Clean up tests a little --- tests/TestConf.php | 31 +++++++++++++++++-------------- tests/TestLang.php | 37 +++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/tests/TestConf.php b/tests/TestConf.php index e151af84..59251f1e 100644 --- a/tests/TestConf.php +++ b/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' => ' "xx");', + 'confNotArray' => ' ' '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' - "xx" -); -VALID_CONFIGURATION_FILE; - file_put_contents(self::$path."/confGood",$validConf); - file_put_contents(self::$path."/confNotArray", 'assertException("fileCorrupt", "Conf"); + $conf = new Conf(self::$path."/confEmpty"); + } + + /** + * @depends testImportFile */ function testImportFileUnreadable() { $this->assertException("fileUnreadable", "Conf"); diff --git a/tests/TestLang.php b/tests/TestLang.php index d9fb3c3e..be07fa83 100644 --- a/tests/TestLang.php +++ b/tests/TestLang.php @@ -9,26 +9,26 @@ class TestLang extends \PHPUnit\Framework\TestCase { static $vfs; static $path; - - const FILES = [ - 'en.php' => ' "and the Philosopher\'s Stone"];', - 'en-ca.php' => ' ' "and the Sorcerer\'s Stone"];', - 'fr.php' => ' "à l\'école des sorciers"];', - 'ja.php' => ' "賢者の石"];', - // corrupt files - 'it.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' => ' "and the Philosopher\'s Stone"];', + 'en-ca.php' => ' ' "and the Sorcerer\'s Stone"];', + 'fr.php' => ' "à l\'école des sorciers"];', + 'ja.php' => ' "賢者の石"];', + // corrupt files + 'it.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/"))); } } \ No newline at end of file