我想开始使用PHPUnit的与Zend测试我的Zend框架应用程序。 我能运行在命令行PHPUnit命令phpunit --configuration phpunit.xml
。 我试过下面这个教程是基于关闭马修纬二路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,梨是最新的,和我有最新的PHPUnit。
更新如果我改变我的bootstrap.php从马修纬二路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);
我继续获取有关的Symfony从学说的错误。 我保证我安装pear.symfony.com/Yaml为好。 所以还是坏。
如果我删除从我app.ini学说为参考,我测试的应用程序(这意味着它不会被加载),我仍然得到错误。 它几乎感觉像装载机为三个部分(PHPUnit的,ZF,教义)是各自为战。 有没有解决的办法?
第二次更新:我降级PHPUnit来3.4.15,我仍然有这个问题。 我的下一步是去从PHP 5.4至5.3.x.
第三次更新:我现在是在PHP 5.3.10和我看到了同样的错误。
如果您需要了解更多信息,请让我知道。