我正在进入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)移动到测试/应用程序中,我仍然收到相同的错误。 –