diff --git a/.gitignore b/.gitignore index 2e66435..f6a98c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.settings /.project /.cache +/tests/report diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index d51bcc7..2b2fc8a 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -34,6 +34,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase /** * @expectedException Exception + * @expectedExceptionMessage Configuration variable */ public function testArrayAsParam() { @@ -48,10 +49,10 @@ class ConfigTest extends PHPUnit_Framework_TestCase $new_arr = Config::get(0); $this->assertEquals('ConfigArray', get_class($new_arr)); $this->assertEquals('four', $new_arr->offsetGet(4)); - $this->assertEquals(1, $new_arr->offsetGet('one')); + $this->assertEquals(1, $new_arr->one); $this->assertNotEquals(1, $new_arr->offsetGet('two')); - $new_arr->offsetGet(24); + $new_arr->some; } } \ No newline at end of file diff --git a/tests/LoadTest.php b/tests/LoadTest.php index ea7d086..b8826b2 100644 --- a/tests/LoadTest.php +++ b/tests/LoadTest.php @@ -25,14 +25,21 @@ class LoadTest extends PHPUnit_Framework_TestCase public static $file_contents; public static $autoload_array; + + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + $this->setPreserveGlobalState(false); + return parent::run($result); + } + /** * @TODO: Load->buildAutoload() should recieve AutoloadBuilder as a parameter * @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can cause error. */ public function setUp() { - self::$file_contents = ' "/lib/core/model/Db.php", "RedisDebug" => "/lib/core/redis/RedisDebug.php"); ?>'; - self::$autoload_array = array('Db' => '/lib/core/model/Db.php', 'RedisDebug' => '/lib/core/redis/RedisDebug.php'); + self::$file_contents = ' "/lib/core/model/Db.php", "DbDriver" => "/lib/core/model/DbDriver.php"); ?>'; + self::$autoload_array = array('Db' => '/lib/core/model/Db.php', 'DbDriver' => '/lib/core/model/DbDriver.php'); vfsStreamWrapper::register(); $this->root = vfsStream::create( @@ -45,9 +52,7 @@ class LoadTest extends PHPUnit_Framework_TestCase ), 'model' => array( 'Db.php' => '', - ), - 'redis' => array( - 'RedisDebug.php' => '' + 'DbDriver.php' => '' ), 'Registry.php' => '', 'Load.php' => '', @@ -97,25 +102,6 @@ class LoadTest extends PHPUnit_Framework_TestCase $this->assertEquals(self::$autoload_array, $autoload); } - /** - * @TODO: Load::autoload() needs self::$autoload = require(self::$file); after self::buildAutoload(); - */ - public function testDebugAutoload() - { - $this->setUp(); - Load::setAutoloadFrom(self::$file); - - $autoload = require(self::$file); - $this->assertNotEmpty($autoload); - - if (!defined('DEBUG')) { - define('DEBUG', true); - } - Load::autoload('Some'); - Load::autoload('RedisDebug'); - } - - public function testAutoloadArrayExists() { $this->assertFileExists(self::$file); @@ -140,10 +126,29 @@ class LoadTest extends PHPUnit_Framework_TestCase public function testAutoloadGetFilePath() { $autoload = require(self::$file); - $this->assertNotEmpty(Load::getFilePath('RedisDebug')); + $this->assertNotEmpty(Load::getFilePath('DbDriver')); } /** + * @TODO: Load::autoload() needs self::$autoload = require(self::$file); after self::buildAutoload(); + * @runInSeparateProcess + */ + public function testDebugAutoload() + { + $this->setUp(); + Load::setAutoloadFrom(self::$file); + + $autoload = require(self::$file); + $this->assertNotEmpty($autoload); + + if (!defined('DEBUG')) { + define('DEBUG', true); + } + Load::autoload('Some'); + Load::autoload('DbDriver'); + } + + /** * @TODO: Load::getFilePath - check for wrong index * @expectedException PHPUnit_Framework_Error */ @@ -153,6 +158,7 @@ class LoadTest extends PHPUnit_Framework_TestCase $this->assertNotEmpty(Load::getFilePath('anton')); } + protected function newCallback($className) { switch ($className) { diff --git a/tests/classes/EnvTest.php b/tests/classes/EnvTest.php index bea75fd..4e80345 100644 --- a/tests/classes/EnvTest.php +++ b/tests/classes/EnvTest.php @@ -15,9 +15,13 @@ require_once dirname(__FILE__) . '/../../app/router/Router.php'; require_once dirname(__FILE__) . '/../../app/FrontController.php'; require_once dirname(__FILE__) . '/../../classes/Env.class.php'; + class EnvTest extends PHPUnit_Framework_TestCase { + /** + * @runInSeparateProcess + */ public function testGetRequestUri() { if(!defined('DEBUG')) { @@ -29,8 +33,14 @@ class EnvTest extends PHPUnit_Framework_TestCase $this->assertEquals('/test/index.php', Env::getRequestUri()); } + /** + * @runInSeparateProcess + */ public function testTrimBaseRequestUri() { + if(!defined('DEBUG')) { + define('DEBUG', false); + } $class = new ReflectionClass('Env'); $this->started = $class->getProperty('request'); $this->started->setAccessible(true); diff --git a/tests/exception/ErrorHandlerTest.php b/tests/exception/ErrorHandlerTest.php index 37cfb82..13ec3b4 100644 --- a/tests/exception/ErrorHandlerTest.php +++ b/tests/exception/ErrorHandlerTest.php @@ -56,7 +56,23 @@ class ErrorHandlerTest extends PHPUnit_Framework_TestCase $this->assertStringStartsWith('', $result); $this->assertStringEndsWith('', $result); } - + } + + /** + * @TODO: ErrorHandler::wrapTrace not used + * @TODO: nl2br() adds html
but leaves original linebreak line \n + */ + public function testWrapTrace() + { + $class = new ReflectionClass('ErrorHandler'); + $method = $class->getMethod('WrapTrace'); + $method->setAccessible(true); + $result = $method->invoke(null, "first line\nsecond line"); + $this->assertEquals("first line
\nsecond line
", $result); + $result = $method->invoke(null, "first line\r\nsecond line"); + $this->assertEquals("first line
\r\nsecond line
", $result); + $result = $method->invoke(null, "first line\r\n\r\nsecond line"); + $this->assertEquals("first line
\r\n
\r\nsecond line
", $result); } public function tearDown()