From eac90243793cf8ba3da2117ac2d76efbcec24e53 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Mon, 15 Feb 2016 21:04:47 +0000 Subject: [PATCH] Usprawnienia wczytywania UTF-8 w module kino --- tests/Core/BotSessionTest.php | 72 ++++++++++++++++++++---------------- 1 files changed, 40 insertions(+), 32 deletions(-) diff --git a/tests/Core/BotSessionTest.php b/tests/Core/BotSessionTest.php index 1b2209f..62a79d7 100644 --- a/tests/Core/BotSessionTest.php +++ b/tests/Core/BotSessionTest.php @@ -1,68 +1,77 @@ <?php class BotSessionTest extends PHPUnit_Framework_TestCase { - function testSessionFolder() { - $dbFolder = dirname(__FILE__).'/../../database'; + private static $dataFolder; + private static $legacyFolder; + + private static function tmpdir() { + $tmpName = tempnam(sys_get_temp_dir(), 'Bot'); + unlink($tmpName); + mkdir($tmpName); + return $tmpName; + } + + private static function rmdir($dir) { + foreach(glob($dir.'/*', GLOB_NOSORT) as $name) { + if($name == '.' || $name == '..') continue; + + if(is_dir($name)) { + self::rmdir($name); + } else { + unlink($name); + } + } - $this->assertTrue(is_writable($dbFolder)); - $this->assertTrue(count(glob($dbFolder.'/*.sqlite')) == 0); + rmdir($dir); } /** - * @depends testSessionFolder + * Create one-time directories for testing purposes. */ + static function setUpBeforeClass() { + self::$dataFolder = self::tmpdir(); + self::$legacyFolder = self::tmpdir(); + } + function testPullEmpty() { - $dbFolder = dirname(__FILE__).'/../../database'; - - $session = new BotSession('test://user1@test'); + $session = new BotSession('test://user1@test', self::$dataFolder, self::$legacyFolder); $session->setClass('test'); $this->assertEquals(array(), $session->pull()); - $this->assertTrue(count(glob($dbFolder.'/*.sqlite')) == 1); + $this->assertTrue(count(glob(self::$dataFolder.'/*.sqlite')) == 1); } /** - * @depends testPullEmpty * @expectedException Exception */ function testSetClass() { - $session = new BotSession('test://user1'); + $session = new BotSession('test://testException', self::$dataFolder, self::$legacyFolder); $session->pull(); } - /** - * @depends testPullEmpty - */ function testLegacyImport() { - $dbFolder = dirname(__FILE__).'/../../database'; - $oldDbFolder = $dbFolder = dirname(__FILE__).'/../../db'; - $data = array('test' => true, 'other' => 'yes, sir!'); $data_serialized = serialize($data); - $this->assertTrue(mkdir($oldDbFolder)); - $this->assertTrue(is_writable($oldDbFolder)); - $this->assertTrue(mkdir($oldDbFolder.'/test')); + $this->assertTrue(mkdir(self::$legacyFolder.'/test')); - $filename = $oldDbFolder.'/test/testUser.ggdb'; + $filename = self::$legacyFolder.'/test/legacyUser.ggdb'; $this->assertEquals(strlen($data_serialized), file_put_contents($filename, $data_serialized)); $this->assertEquals($data_serialized, file_get_contents($filename)); - $session = new BotSession('test://testUser@test'); + $session = new BotSession('test://legacyUser@test', self::$dataFolder, self::$legacyFolder); $session->setClass('test'); $this->assertTrue(isset($session->test)); $this->assertEquals($data, $session->pull()); $this->assertFalse(file_exists($filename)); - $this->assertTrue(rmdir($oldDbFolder.'/test')); - $this->assertTrue(rmdir($oldDbFolder)); } /** * @depends testPullEmpty */ function testManualExample() { - $session = new BotSession('test://user1@test'); + $session = new BotSession('test://user1@test', self::$dataFolder, self::$legacyFolder); $session->setClass('test'); // Ustawienie pojedynczej wartoĊci @@ -108,7 +117,7 @@ * @depends testManualExample */ function testManualExample2() { - $session = new BotSession('test://user1@test'); + $session = new BotSession('test://user1@test', self::$dataFolder, self::$legacyFolder); $session->setClass('test'); $array = array( @@ -124,13 +133,12 @@ $this->assertEquals(array(), $session->pull()); } - /** - * @depends testManualExample2 - */ - function testCleanup() { - $dbFolder = dirname(__FILE__).'/../../database'; - foreach(glob($dbFolder.'/*.sqlite') as $file) { + static function tearDownAfterClass() { + foreach(glob(self::$dataFolder.'/*.sqlite') as $file) { unlink($file); } + + self::rmdir(self::$dataFolder); + self::rmdir(self::$legacyFolder); } } -- Gitblit v1.9.1