使用 Zend_Test 引导 Zend_Application

发布于 2024-09-13 10:41:43 字数 1000 浏览 6 评论 0原文

在文档中提供的引导代码看起来

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 的原因是 来自 zendcasts 的 jon lebensold 扩展了 ControllerTestCase 以在单独的类中处理所有这些引导。我想,如果我可以将代码移动到 bootstrap.php 的 1 个位置,而不是扩展类,那不是更好吗

in the docs the provided code for bootstrapping looks like

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

i was curious why when i tried

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

it failed. also when i tried moving bootstrapping the application in bootstrap.php it fails too

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

the reason why i thought of moving this to bootstrap.php is jon lebensold from zend casts extended the ControllerTestCase to handle all this bootstrapping in a separate class. i thought instead of extending the class, if i can move the code into the bootstrap.php in 1 place wont it be better

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙味迷妹 2024-09-20 10:41:43

这就是我的 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';

This is what my ControllerTestCase.php looks like:

<?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';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文