ZendFrameworkアプリケーションでZendTestでPHPUnitの使用を開始しようとしています。コマンドラインからPHPUnitコマンドを実行できますphpunit --configuration phpunit.xml
。MatthewWeierO'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
私が間違っていることについての手がかりはありますか?私はPHP5.4、Windows 7、XAMPP 8.0を使用しており、Pearは最新であり、最新のPHPUnitを使用しています。
Bootstrap.phpをMatthewWeierO'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参照を削除しても(つまり、ロードされない)、エラーが発生します。3つの部分(PHPUnit、ZF、Doctrine)のそれぞれのローダーが互いに戦っているように感じます。これを回避する方法はありますか?
2番目の更新: PHPUnitを3.4.15にダウングレードしましたが、まだこの問題が発生しています。次のステップは、PHP5.4から5.3.xに移行することです。
3番目の更新:現在PHP 5.3.10を使用していますが、同じエラーが表示されます。
さらに必要な情報がありましたら、お知らせください。