PHP 5.3.4、Zend 1.11.11、およびPHPUnit3.7.1でWampServerを実行しています。私のプロジェクトの構造は、テストフォルダーが次のように編成されたデフォルトのZendレイアウトです。
tests/
application/
library/
bootstrap.php
phpunit.xml
IndexControllerTest.php
application/
と の両方library/
が空の場合。phpunit IndexControllerTest
このベースケースは、ターミナルから実行でき、問題なくテストを実行できる現在のセットアップで正常に機能します。IndexControllerTest.phpを別の場所(たとえば、application/
ディレクトリ内)に移動するとすぐに問題が発生します。次に、phpunitから致命的なエラーを受け取ります。
PHP Fatal error: Class 'Zend_Test_PHPUnit_ControllerTestCase' not found in
X:\Program Files (x86)\Wamp\www\Local_site\Zend\login\tests\application\IndexControllerTest.php
on line 3
間違えない限り、オートローダーがこれを処理するはずですrequire()
が、テストファイルの場所を変更するとすぐに問題が発生します。phpunit.xmlファイルを何度も微調整しようとしましたが、それが私の問題の原因なのか、bootstrap.phpにあるのか、コードにあるのかわかりません。任意の洞察をいただければ幸いです。正しい方向に少しでも。関連するファイルは次のとおりです。
phpunit.xml
<phpunit bootstrap="./bootstrap.php">
<testsuites>
<testsuite name="My Project">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<!-- If Zend Framework is inside your project's library, uncomment this filter -->
<whitelist>
<directory suffix=".php">/library/Zend</directory>
</whitelist>
</filter>
</phpunit>
bootstrap.php
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
IndexControllerTest.php
<?php
class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
protected $application;
public function setUp()
{
// Assign and instantiate in one step:
$this->bootstrap = new Zend_Application(
'testing',
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
public function testTrue()
{
$this->assertTrue(true);
}
}
ゴールデンインターネットからの他の提案に従って、php /php.iniinclude_pathも次のように変更しました。
include_path=".;X:\Program Files (x86)\Wamp\bin\php\php5.3.4\pear;X:\Program Files (x86)\Wamp\bin\php\php5.3.4\pear\PHPUnit"
明示的に含める必要がありますZend/Test/PHPUnit/ControllerTestCase.php
か?私はすでに何百もの解決策を試しましたが、私は盲目的に飛んでいたので、私は非常に近くにいて、それを知らなかったかもしれません。