Browse Source

some modifications for test isolation in DEBUG environment

master
Anton Grebnev 13 years ago
parent
commit
c7993193de
  1. 1
      .gitignore
  2. 5
      tests/ConfigTest.php
  3. 56
      tests/LoadTest.php
  4. 10
      tests/classes/EnvTest.php
  5. 18
      tests/exception/ErrorHandlerTest.php

1
.gitignore

@ -1,3 +1,4 @@
/.settings
/.project
/.cache
/tests/report

5
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;
}
}

56
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 = '<?php return array("Db" => "/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 = '<?php return array("Db" => "/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) {

10
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);

18
tests/exception/ErrorHandlerTest.php

@ -56,7 +56,23 @@ class ErrorHandlerTest extends PHPUnit_Framework_TestCase
$this->assertStringStartsWith('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', $result);
$this->assertStringEndsWith('</html>', $result);
}
}
/**
* @TODO: ErrorHandler::wrapTrace not used
* @TODO: nl2br() adds html <br /> 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("<code>first line<br />\nsecond line</code>", $result);
$result = $method->invoke(null, "first line\r\nsecond line");
$this->assertEquals("<code>first line<br />\r\nsecond line</code>", $result);
$result = $method->invoke(null, "first line\r\n\r\nsecond line");
$this->assertEquals("<code>first line<br />\r\n<br />\r\nsecond line</code>", $result);
}
public function tearDown()

Loading…
Cancel
Save