我正在進入Zend和單元測試階段,所以對我一無所知。我使用PHP 5.3.4,Zend 1.11.11和PHPUnit 3.7.1運行Wamp Server。我的項目結構是默認的Zend佈局,組織成這樣的測試文件夾:當基本「測試」文件夾之外時,PHPUnit找不到Zend_Test_PHPUnit_ControllerTestCase
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.ini中的include_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
?我已經嘗試了數以百計的解決方案,但我一直在盲注,所以我本可以非常接近,甚至不知道它。
從哪裏運行phpunit當你移動* Test.php文件?在這種情況下配置文件是否被加載? – cweiske
如在,我運行'phpunit應用程序/ IndexControllerTest'如果IndexControllerTest.php位於tests/application/IndexControllerTest.php?是的,我做了(和同樣的錯誤),並沒有產生任何錯誤的配置文件未被加載。即使我將配置文件(我假設是phpunit.xml)移動到測試/應用程序中,我仍然收到相同的錯誤。 –