some modifications for test isolation in DEBUG environment

This commit is contained in:
Anton Grebnev
2011-10-28 13:50:15 +04:00
parent 6cee0efa6f
commit c7993193de
5 changed files with 62 additions and 28 deletions

View File

@ -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) {