2010-08-07 10 views
1

dans la documentation du code fourni pour bootstrapping ressembleAmorçage Zend_Application avec 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(); 
} 

j'étais curieux de savoir pourquoi quand j'ai essayé

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

il a échoué. aussi quand je l'ai essayé de déplacer bootstrapping application dans bootstrap.php il échoue trop

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

la raison pour laquelle je pensais de passer à ce Bootstrap.php est jon lebensold from zend casts étendu la ControllerTestCase pour gérer tout cela bootstrapping dans une catégorie distincte. je pensais au lieu d'étendre la classe, si je peux déplacer le code dans le bootstrap.php en 1 place Wont mieux

Répondre

0

C'est ce que mon ControllerTestCase.php ressemble:

<?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';