我正在尝试将 PHPUnit 与 Zend Test 一起用于我的 Zend Framework 应用程序。我可以从命令行运行 PHPUnit 命令phpunit --configuration phpunit.xml
。我已经尝试按照基于 Matthew Weier O'Phinney 的博客文章的教程进行操作。当 PHPUnit 尝试写入日志文件时出现错误。这是我的 phpunit.xml
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuite name="Zend Framework Tests">
<directory>./</directory>
</testsuite>
<!-- Optional filtering and logging settings -->
<filter>
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>
<exclude>
<directory suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="./log/testdox.html"/>
</logging>
</phpunit>
我的测试引导程序:
<?php
//Set app paths and environment
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');
define('TEST_PATH', BASE_PATH . '/tests');
define('APPLICATION_ENV', 'testing');
//Set include path
set_include_path('.' . PATH_SEPARATOR . BASE_PATH . '/library' . PATH_SEPARATOR . get_include_path());
//Set the default timezone
date_default_timezone_set('America/Chicago');
?>
还有我希望我的测试控制器扩展的 ControllerTestCase:
<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public $_application;
public function setUp()
{
//Override the parent to solve an issue with not finding the correct module
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
}
?>
PHPUnit 尝试写入日志文件时出现的错误是:
Fatal error: Class 'Symfony\Component\Console\Command\Command' not found in C:\repositories\myfirstzend.com\includes\library\Doctrine\DBAL\Tools\Console\Command\ImportCommand.php on line 38
关于我做错了什么的任何线索?我在 PHP 5.4、Windows 7、XAMPP 8.0 上,Pear 是最新的,我有最新的 PHPUnit。
更新如果我将我的 Bootstrap.php 更改为 Matthew Weier O'Phinney 博客中的以下内容:
<?php
/*
* Start output buffering
*/
ob_start();
/*
* Set error reporting to the level to which code must comply.
*/
error_reporting( E_ALL | E_STRICT );
/*
* Set default timezone
*/
date_default_timezone_set('GMT');
/*
* Testing environment
*/
define('APPLICATION_ENV', 'testing');
/*
* Determine the root, library, tests, and models directories
*/
$root = realpath(dirname(__FILE__) . '/../');
$library = $root . '/library';
$tests = $root . '/tests';
$models = $root . '/application/models';
$controllers = $root . '/application/controllers';
/*
* Prepend the library/, tests/, and models/ directories to the
* include_path. This allows the tests to run out of the box.
*/
$path = array(
$models,
$library,
$tests,
get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $path));
/**
* Register autoloader
*/
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
/**
* Store application root in registry
*/
Zend_Registry::set('testRoot', $root);
Zend_Registry::set('testBootstrap', $root . '/application/bootstrap.php');
/*
* Unset global variables that are no longer needed.
*/
unset($root, $library, $models, $controllers, $tests, $path);
我继续从 Doctrine 收到有关 Symfony 的错误。我确保我也安装了 pear.symfony.com/Yaml。所以还是坏了。
如果我从我正在测试的应用程序的 app.ini 中删除 Doctrine 引用(这意味着它没有被加载),我仍然会收到错误消息。几乎感觉这三个部分(PHPUnit、ZF、Doctrine)中的每一个的加载器都在互相争斗。有没有解决的办法?
第二次更新:我将 PHPUnit 降级到 3.4.15,但我仍然遇到这个问题。我的下一步是从 PHP 5.4 升级到 5.3.x。
第三次更新:我现在在 PHP 5.3.10 上看到同样的错误。
如果您需要更多信息,请告诉我。