2010-08-07 26 views
1

在文档中进行引导所提供的代码看起来像自举Zend_Application与Zend_Test

protected $application; 
public function setUp() { 
    $this->bootstrap = array($this, 'appBootstrap'); 
    parent::setUp(); 
} 
public function appBootstrap() { 
    $this->application = new Zend_Application(...); 
    $this->application->bootstrap(); 
} 

我很好奇,为什么当我试图

protected $application; 
public function setUp() { 
    $this->application = new Zend_Application(...); 
    $this->application->bootstrap(); 
    parent::setUp(); 
} 

失败。还当我试图移动在bootstrap.php中自举程序失败过

// bootstrap.php 
... 
$application = new Zend_Application(...); 
$application->bootstrap(); 

为什么我认为移动这bootstrap.php中的是jon lebensold from zend casts扩展ControllerTestCase来处理这一切的引导在一个单独的类的原因。我想,而不是扩展类,如果我能在1处的代码移动到的bootstrap.php不会是更好

回答

0

这是我ControllerTestCase.php是什么样子:

<?php 
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase 
{ 
    public function setUp() 
    { 

     $this->bootstrap = new Zend_Application(
      APPLICATION_ENV, 
      APPLICATION_PATH . '/configs/application.ini' 
     ); 
     parent::setUp(); 
    } 
} 

TestHelper.php (Bootstrap)

<?php 
define('BASE_PATH', realpath(dirname(__FILE__) . '/../public')); 
define('APPLICATION_PATH', realpath(BASE_PATH . '/../application')); 

set_include_path(implode(PATH_SEPARATOR, array(
    '.', 
    realpath(APPLICATION_PATH . '/../library'), 
    get_include_path() 
))); 

define('APPLICATION_ENV', 'testing'); 

require_once "Zend/Loader/Autoloader.php"; 

$loader = Zend_Loader_Autoloader::getInstance(); 
$loader->setFallbackAutoloader(true); 
$loader->suppressNotFoundWarnings(false); 

require_once 'ControllerTestCase.php';