Domanda

nella documentazione del codice fornito per l'avvio assomiglia

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

ero curioso di sapere perchè quando ho cercato

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

non è riuscito. anche quando ho provato spostamento bootstrap l'applicazione in bootstrap.php fallisce troppo

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

la ragione per cui ho pensato di spostare questo per bootstrap.php è Jon Lebensold da calchi Zend esteso il ControllerTestCase per gestire tutto questo bootstrap in una classe separata. ho pensato invece di estendere la classe, se posso spostare il codice nella bootstrap.php in 1 posto solito sarebbe meglio

È stato utile?

Soluzione

Questo è ciò che il mio ControllerTestCase.php appare come:

<?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';
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top