2013-08-20 60 views
1

我一直在嘗試運行FunctionalTest,它擴展了Symfony \ Bundle \ FrameworkBundle \ Tests \ Functional \ WebTestCase並沒有那麼成功。Symfony 2上的功能測試 - 問題與默認autoload.php.dist

的問題是:

  1. 在FrameworkBundle代碼\測試\功能\應用\ AppKernel.php嘗試加載autoload.php.dist在框架束(不是一個在應用程序/ )。

  2. 然後autoload.php.dist會嘗試加載該路徑中不存在的vendor \ autoload.php。

如果我刪除autoload.php.dist在FrameworkBundle那麼一切都很好,但我想避免這樣做,因爲每次我做的作曲家更新我便要刪除特定的罰款。

我想知道我做錯了什麼。

從控制檯確切的錯誤張貼下面您的信息:

Configuration read from D:\xampp\htdocs\demo\app\phpunit.xml. dist

  1. require_once() called at [D:\xampp\htdocs\demo\vendor\sym fony\symfony\src\Symfony\Bundle\FrameworkBundle\Tests\Functional\app\AppKernel.p hp:26]

  2. require_once(D:\xampp\htdocs\demo\vendor\symfony\symfony\ src\Symfony\Bundle\FrameworkBundle\Tests\Functional\app\AppKernel.php) called at [D:\xampp\htdocs\demo\vendor\symfony\symfony\src\Symfony\Bun dle\FrameworkBundle\Tests\Functional\WebTestCase.php:47]

Fatal error: main(): Failed opening required 'D:\xampp\htdocs\demo\vendor\symfony\symfony/vendor/autoload.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\demo\vendor\symfony\sym fony\autoload.php.dist on line 9

測試類只需擴展WebTestCase與設置是這樣的:

static::$kernel = static::createKernel(array('test_case')); 
static::$kernel->boot(); 
$this->containter = static::$kernel->getContainer(); 
+0

我剛剛在我的unix機器上運行了一個測試,它工作正常。沒有方便的Windows機器。你只需要MyTest擴展WebTestCase?你有沒有得到測試在xampp之前運行?我在家使用xampp並沒有問題。什麼版本的symfony? – Cerad

+0

我所有的測試都運行良好,但這些只是基本的單元測試,這是我第一次擴展WebTestCase。你是對的,MyTest只是擴展了WebTestCase,我也在setUp中模擬了容器。讓我補充一點,在 – mr1031011

+0

這個問題中您是使用phpunit -C提供的phpunit.xml文件,還是僅僅通過在app目錄中運行phpunit?你有沒有對phpunit.xml做任何調整?那裏有一條引導線。 – Cerad

回答

4

好。我看到了問題。您正在從Tests \ Functional \ WebTestCase進行擴展。這實際上是測試WebTestCase的測試。你想從Test \ WebTestCase擴展。

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 

class PersonRepositoryTest extends WebTestCase 
{ 
    public function testProject() 
    { 
     $client = static::createClient(); 

     $manager = $client->getContainer()->get('cerad_person.manager'); 

,你可能想要得到一個或兩個以上使用所示的$客戶端線的工作。所有的設置都可能有點棘手。

+0

非常感謝。我現在覺得很愚蠢。 – mr1031011