CLI( phpunit --configuration phpunit.xml ) を使用して、テストを正常に実行できます。
tests ディレクトリには次のような階層があります。
tests
├── application
│ ├── bootstrap.php
│ ├── controllers
│ │ └── ControllerTest.php
│ └── FirstTest.php
├── library
├── log
│ ├── report
│ └── testdox.html
└── phpunit.xml
ファイルの内容
phpunit.xml
<phpunit bootstrap="./application/bootstrap.php" colors="true"> <testsuite name="Webguide Unit Test"> <directory>./</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">../library/</directory> <directory suffix=".php">../application/</directory> <exclude> <directory suffix=".phtml">../application/</directory> <file>../application/Bootstrap.php</file> <file>../application/controllers/ErrorController.php</file> </exclude> </whitelist> </filter> <logging> <log highlowerbound="80" lowupperbound="50" highlight="true" yui="true" charset="UTF-8" target="./log/report" type="coverage-html"/> <log target="./log/testdox.html" type="testdox-html"/> </logging> </phpunit>
アプリケーション/bootstrap.php
<?php error_reporting(E_ALL | E_STRICT); date_default_timezone_set('GMT'); define('APPLICATION_ENV', 'testing'); define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application')); define('APPLICATION_CONFIG', APPLICATION_PATH . '/configs/application.ini'); set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path() ))); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); require_once 'Zend/Application.php';
(Zend Test をセットアップしたい人のために、ここに参考文献があります: Unit Testing with Zend Framework 1.11 and PHPUnit )
Zend Studio 9 でテストを実行しているときに、次のエラー メッセージが表示 されました。
コンソールでは、出力は次のようになります。
*コンパイル エラー: /home/coiby/ZendStudio/plugins/com.zend.php.phpunit_9.0.1.201112141951/resources/ZendPHPUnit.php 行 109 - require_once() [function.require]: 必要な '/var/www を開けませんでした/webguide/tests/controllers/ControllerTest.php' (include_path='/var/www/webguide/library:.:/usr/share/php::/var/www/webguide:')*
上記の情報に従って、ディレクトリ "controllers/ControllerTest.php" を上のディレクトリに移動しました。つまり、' /var/www/webguide/tests/controllers/ControllerTest.php
' が存在します。
しかし、エラーがあります。コンソールの出力は次のとおりです。
*デバッグ エラー: /webguide/library/Doctrine/Common/Cache/ApcCache.php 行 52 - 未定義関数 Doctrine\Common\Cache\apc_fetch() の呼び出し*
これはどのように起こりますか?PHP APC を pear でインストールしました。このモジュールは phpinfo() の結果にあります。そして、テストは CLI を介して正常に実行されます。私がチェックしたもう 1 つのことは、php のインクルード パスです。既に /usr/share/php を Zend Studio のインクルード パスに追加しています。
誰か提案してくれませんか?
ありがとう!