我正在努力让 phpunit 使用我的 symfony2 项目在 netbeans 中工作。
我已经在我的项目根目录中进行了子文件夹测试。尝试将项目链接到 phpunit.xml.dist 和 bootstrap.php.cash。并在该测试文件夹中创建了一个 MyProjectTestSuite.php 并将其放入我的项目属性中。
但这一切都让我犯了错误:
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "C:\Program Files\NetBeans 7.1.2\php\phpunit\NetBeansSuite.php".' in C:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:125
Stack trace:
#0 C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'C:\Program File...')
#1 C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#2 C:\xampp\php\phpunit(53): PHPUnit_TextUI_Command::main()
#3 {main}
thrown in C:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 125
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "C:\Program Files\NetBeans 7.1.2\php\phpunit\NetBeansSuite.php".' in C:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:125
Stack trace:
#0 C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'C:\Program File...')
#1 C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#2 C:\xampp\php\phpunit(53): PHPUnit_TextUI_Command::main()
#3 {main}
thrown in C:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 125
并且测试没有被执行。
myprojectetssuite.php 看起来像这样。
<?php
use Symfony\Component\Finder\Finder;
class MyProjectTestSuite extends PHPUnit_Framework_TestSuite
{
public static function suite()
{
$suite = new MyProjectTestSuite();
$finder = new Finder();
// ---------- COMMENT OUT TO TEST A SPECIFIC FILE ----------
// $suite->addTestFile('../src/<yourbundle>/DefaultBundle/Tests/Controller/SomeControllerTest.php');
// return $suite;
// ----------
echo "Searching for test cases...\n\n";
foreach ($finder->files()->in('../src/')->name('*Test.php') as $file) {
if (preg_match('%\\Tests\\[\w-\\]+Test.php%i', $file->getPathName())) {
echo 'Adding test : ' . $file->getPathName() . "\n";
$suite->addTestFile($file->getPathName());
}
}
echo "\n";
return $suite;
}
}