2013-06-24 96 views
2

我試圖讓PHPUnit工作;我以前沒有用過它。如果我在CLI中運行phpunit,它可以工作,但通過一個腳本(這是我正在尋找的)它不會。這是輸出我得到的(注意級後兩個空格):PHPUnit丟失類名(ReflectionClass類不存在錯誤)

Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /usr/local/share/pear/PHPUnit/Util/Test.php:295 
Stack trace: 
#0 /usr/local/share/pear/PHPUnit/Util/Test.php(295): ReflectionClass->__construct('') 
#1 /usr/local/share/pear/PHPUnit/Util/Test.php(576): PHPUnit_Util_Test::parseTestMethodAnnotations(false, false) 
#2 /usr/local/share/pear/PHPUnit/Util/Test.php(350): PHPUnit_Util_Test::getBooleanAnnotationSetting(false, false, 'backupGlobals') 
#3 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(458): PHPUnit_Util_Test::getBackupSettings(false, false) 
#4 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(834): PHPUnit_Framework_TestSuite::createTest(Object(ReflectionClass), false) 
#5 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(212): PHPUnit_Framework_TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod)) 
#6 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass)) 
#7 /var/www/www.s in /usr/local/share/pear/PHPUnit/Util/Test.php on line 295 

看來,類名被丟在addTestMethod。這是我的代碼:

<?php 
require_once 'PHPUnit/Autoload.php'; 

class MyTestCase extends PHPUnit_Framework_TestCase { 
    public function testSubtraction() { 
     $this->assertEquals(2 - 2, 0); 
    } 
    public function testAddition() { 
     $this->assertEquals(2 + 2, 4); 
    } 
} 
$c = new MyTestCase(); 

$suite = new PHPUnit_Framework_TestSuite(); 
$suite->addTestSuite('MyTestCase'); 
PHPUnit_TextUI_TestRunner::run($suite); 

我是否設置錯誤?

這裏是版本:

Installed packages, channel pear.phpunit.de: 
============================================ 
Package   Version State 
File_Iterator  1.3.3 stable 
PHPUnit   3.7.21 stable 
PHPUnit_MockObject 1.2.3 stable 
PHP_CodeCoverage 1.2.11 stable 
PHP_Timer   1.0.4 stable 
PHP_TokenStream 1.1.5 stable 
Text_Template  1.1.4 stable 

PHP 5.4

反思做的工作,我用我自己的腳本。希望這是我的設置,我真的不想修改PHPUnit ...肯定它在別處工作。

+0

你以某種方式解決了這個問題嗎? –

回答

0

的東西是錯誤的:

'Class does not exist' 
    ^
     `- normally the classname is given here 

正如你可以看到你的錯誤信息是丟失的東西或PHPUnit的嘗試創建一個TestCase無中生有。檢查你的測試文件夾中沒有多餘的/不完整的文件。或者類似的東西。這只是基於錯誤消息的猜測,如果我是你,我會在調試會話中解決這個問題,以便真正瞭解發生的情況。這包括刪除 - 調試測試會話並逐步完成並可能將調試代碼添加到phpunit安裝中。保重和備份。