Pergunta

Nos documentos, o código fornecido para o bootstrapping parece

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

Fiquei curioso por que quando tentei

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

falhou. Além disso, quando tentei mover o bootstrapping do aplicativo no bootstrap.php, ele também falha

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

A razão pela qual pensei em mudar isso para bootstrap.php é Jon Lebensold de Zend elenco estendeu o controlador para lidar com todo esse bootstrapping em uma classe separada. Eu pensei em vez de estender a classe, se eu puder mover o código para o bootstrap.php em 1 lugar, não será melhor

Foi útil?

Solução

É assim que meu controlertestcase.php se parece:

<?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';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top