2012-06-28 43 views
2

我們剛開始針對我們的CI單元測試我們的應用程序;PHPUnit在使用Symfony2成功完成測試後拋出錯誤消息

[email protected]:~/public$ phpunit -c app/ --strict src/Acme/Bundle/SomeBundle/Tests/Controller/SomeControllerTest.php 
PHPUnit 3.6.11 by Sebastian Bergmann. 

Configuration read from /var/www/user/htdocs/public/app/phpunit.xml.dist 

.. 

Time: 5 seconds, Memory: 130.00Mb 

OO (2 tests, 2 assertions) 
PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0 
PHP Stack trace: 
PHP 1. {main}() /usr/bin/phpunit:0 
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:133 

Fatal error: Exception thrown without a stack frame in Unknown on line 0 

Call Stack: 
    0.0001  629992 1. {main}() /usr/bin/phpunit:0 
    0.0023 1235832 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 
    0.0023 1236848 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:133 

迄今爲止唯一的暗示是,它只有在測試中使用的一個(或多個)[見下面的情況:我們已經通過書面運行,但PHPUnit的總是拋出在最後一個錯誤消息第一次測試]在頁面上發出請求,所以它可能以某種方式與會話相關。

$client = static::createClient(); 
$container = $client->getContainer(); 
$uri = $container->getParameter('url_frontend') . '/'; 
$client->request('GET', $uri); 

這裏是我們的phpunit.xml.dist

更新鏈接:

我得到了一個小的更多信息,有關該錯誤本身:

1) Acme\Bundle\SomeBundle\Tests\Controller\SomeControllerTest::testIndexResponseStatusCode 
RuntimeException: PHP Fatal error: Uncaught exception 'ErrorException' with message 'Warning: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp/sessions) in Unknown line 0' in /var/www/user/htdocs/public/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php:67 
Stack trace: 
#0 [internal function]: Symfony\Component\HttpKernel\Debug\ErrorHandler->handle(2, 'Unknown: Failed...', 'Unknown', 0, Array) 
#1 {main} 
    thrown in /var/www/user/htdocs/public/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php on line 67 

回答

0

我們的一個開發者的(經過大量粗口和咒罵)解決了這個問題,過錯是FOS\FacebookBundle\Facebook\FacebookSessionPersistence準確地說,該構造開始自己的會話的事實:

public function __construct($config, Session $session, $prefix = self::PREFIX) 
{ 
    $this->session = $session; 
    $this->prefix = $prefix; 
    $this->session->start(); // he starts a session 

    parent::__construct($config); 
} 

所以我們只寫了我們自己FacebookSessionPersistence類:

# quick workaround as the fb class fails the test as it calls session->start in the construct 
# @see https://github.com/FriendsOfSymfony/FOSFacebookBundle/issues/79 
fos_facebook: 
    class: 
     api: Acme\Bundle\UserBundle\Facebook\FacebookSessionPersistence 

namespace Acme\Bundle\UserBundle\Facebook; 

use FOS\FacebookBundle\Facebook\FacebookSessionPersistence as BaseFacebookSessionPersistence; 
use Symfony\Component\HttpFoundation\Session; 

/** 
* Quick (and dirty) fix for running tests using FosFacebookBundle. 
* only use this class, while testing the application with phpunit 
* 
* @see https://github.com/FriendsOfSymfony/FOSFacebookBundle/issues/79 
*/ 
class FacebookSessionPersistence extends BaseFacebookSessionPersistence 
{ 
    public function __construct($config, Session $session, $prefix = self::PREFIX) 
    { 
     $this->session = $session; 
     $this->prefix = $prefix; 

     // don't start session or call parent constructor 
     //$this->session->start(); 

     //parent::__construct($config); 

    } 
} 

而且在測試配置添加它3210

希望能幫助下一代...

0

我只是猜測,但我認爲引發異常是因爲phpunit嘗試第二次運行(異常拋出在run()方法的開始處)。

在你phpunit.xml.dist嘗試更換:

<testsuites> 
    <testsuite name="Project Test Suite"> 
     <directory>../src/*/*Bundle/Tests</directory> 
     <directory>../src/*/Bundle/*Bundle/Tests</directory> 
    </testsuite> 
</testsuites> 

有:

<testsuites> 
    <testsuite name="Project Test Suite"> 
     <directory>../src/*/*Bundle/Tests</directory> 
    </testsuite> 
</testsuites> 

我覺得第一條規則的兩條路徑相匹配。

+0

沒有幫助: -/thx tough – Hannes