2015-05-14 28 views
1

我與Symfony的2個工作,並試圖讓PHPUnit來使用它,所以我一直所要求-dev的添加到了我的composer.json:不能獲得PHPUnit的工作Symfony的2

"phpunit/phpunit": "4.6.*" 

拼命地跑這在我的終端命令:

composer update --dev 

做上述的PHPUnit後出現的vendor目錄下。

按照docs的Symfony 2已經PHPUnit的預配置,可通過執行:phpunit -c app/

但它從來沒有工作,我的終端消息是:

Unknown command 「phpunit」 
The program 'phpunit' is currently not installed. You can install it by typing: 
sudo apt-get install phpunit 

即使通過這個./bin/phpunit -c app似乎觸發PHPUnit的無論我寫什麼測試,我總是得到這個:

Configuration read from /home/tomazi/Dev/api.test/app/phpunit.xml.dist 



Time: 66 ms, Memory: 4.25Mb 

No tests executed! 

我的測試:

<?php 

namespace BoltMail\User\InteractionBundle\Tests\Dto\Template; 

class TestTemplateTest extends \PHPUnit_Framework_TestCase 
{ 
    public function testIndex() 
    { 
     $this->assertTrue(true); 
    } 
} 
+0

正在搜索什麼目錄:phpunit.xml.dist – Cerad

+0

取決於配置,本地(到Composer安裝的項目)phpunit可執行文件可能位於'。bin /'或'vendor/bin /'目錄中。這由composer.json中的(可選)'bin' json配置設置。默認是將可執行命令放入'vendor/bin /' –

回答

2

當你從作曲家安裝PHPUnit的你應該從項目目錄運行它

$./bin/phpunit -c app 

,或者如果你想讓它在全球範圍內拼命地跑:

對於全系統安裝通過Composer,您可以運行:

composer global require「phpunit/phpunit = 3.7。*」確保您有 〜/ .composer/vend或/ bin /在你的路徑中。

更新你的問題:

我想你已經通過指定的測試目標解決問題與空測試。只是第二種方式是在應用程序指定目標/ phpunit.xml

<?xml version="1.0" encoding="UTF-8"?> 

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> 
<phpunit 
    backupGlobals    = "false" 
    backupStaticAttributes  = "false" 
    colors      = "true" 
    convertErrorsToExceptions = "true" 
    convertNoticesToExceptions = "true" 
    convertWarningsToExceptions = "true" 
    processIsolation   = "false" 
    stopOnFailure    = "false" 
    syntaxCheck     = "false" 
    verbose      = "true" 
    bootstrap     = "bootstrap.php.cache" > 
<!-- more settings here --> 
    <testsuites> 
     <testsuite name="My Test Suite"> 
      <directory>../src/*/*Bundle/Tests</directory> 
      <directory>../src/*/Bundle/*Bundle/Tests</directory> 
     </testsuite> 
    </testsuites> 
    <filter> 
     <whitelist> 
     <directory>../src</directory> 
     <exclude> 
      <directory>../src/*/*Bundle/Resources</directory> 
      <directory>../src/*/*Bundle/Tests</directory> 
      <directory>../src/*/Bundle/*Bundle/Resources</directory> 
      <directory>../src/*/Bundle/*Bundle/Tests</directory> 
     </exclude> 
     </whitelist> 
    </filter>  
</phpunit> 
+0

你可以看看上面的編輯。 – Tomazi

+0

更新了我的答案 –

1

要麼你有你的PHPUnit的配置文件phpunit.xml.dist到指定的目錄或特定目錄中運行命令或文件

./bin/phpunit -c app/ path/to/your/test/folder