2013-05-18 4 views
12

コメントありがとうございます。私はちょうどZend Framework 1からZF2に移行し始めました。クイックスタートやその他のチュートリアルを実行した後、私はphpunitを使うための「デフォルト」の方法があることに気付きました。それか私はちょうど失われて混乱しています。zendフレームワーク2 + phpunit +複数モジュール+継続的インテグレーション

デフォルトのプロジェクトのためのフォルダ構造は、私の質問は、私はANTとジェンキンスを使用して行う方法、これはPHPUnitのテストスイートのすべてをテストすることです

Project 
| - config 
| | - autoload 
| | | - global.php 
| | | - local.php.dist 
| | - application.config.php 
| - data 
| - module 
| | - Application 
| | | - config 
| | | - src 
| | | - test 
| | | | - ApplicationTest 
| | | | - Bootstrap.php 
| | | | - phpunit.xml 
| | | | - TestConfig.php.dist 
| | | - view 
| | | - Module.php 
| | - Album 
| | | - config 
| | | - src 
| | | - test 
| | | | - AlbumTest 
| | | | - Bootstrap.php 
| | | | - phpunit.xml 
| | | | - TestConfig.php.dist 
| | | - view 
| | | - Module.php 
| - public 
| - vendor 

です。私は個々のモジュールを個別にテストする理由を理解していますが、どのモジュールを適切に自動化して1つのreport.xmlを返すことができるのでしょうか。そして、私がphpunitの設定で各モジュールを指定する必要がなければ、さらに良いでしょう。またはbuild.xml。

ご意見ありがとうございました。

答えて

4

私はそれを理解したときに私自身の質問に答えるのを忘れていました。私は忘れてしまったコミュニティに謝ります...しかし、すべての人にとっては、

のbuild.xml

<target name="phpunit" description="Run unit tests with PHPUnit"> 
    <apply executable="../vendor/bin/phpunit" parallel="false"> 
     <fileset dir="${env.WORKSPACE}/module" > 
      <include name="**/test/phpunit.xml"/> 
     </fileset> 
     <arg value="--configuration" /> 
     <srcfile/> 
    </apply> 
</target> 

そして、各モジュールのphpunit.xml

<phpunit bootstrap="Bootstrap.php"> 
    <testsuites> 
     <testsuite name="Application"> 
      <directory>./</directory> 
     </testsuite> 
    </testsuites> 

<!-- Filters only matter for code coverage reporting --> 
    <filter> 
     <blacklist> 
      <directory>../../../vendor/</directory> 
      <directory>./</directory> 
      <file>../Module.php</file> 
     </blacklist> 
    </filter> 
    <logging> 
     <log type="coverage-html" target="../../../build/coverage" title="Application Module" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/> 
     <log type="coverage-clover" target="../../../build/logs/clover-Application.xml"/> 
     <log type="junit" target="../../../build/logs/junit-Application.xml" logIncompleteSkipped="false"/> 
    </logging> 
</phpunit> 
2

私は以下の構造を使用します。私はテストのフォルダ内のすべてのテストを持っているとモジュールが構成されていると私は同じようにテストを構造化:

Project 
| - config 
| | - autoload 
| | | - global.php 
| | | - local.php.dist 
| | - application.config.php 
| - data 
| - module 
| | - Application 
| | | - config 
| | | - src 
| | | | - Application 
| | | | | - Controller 
| | | | | | - IndexController.php 
| | | | | - Model 
| | | | | | - Foo.php 
| | | | | - Form 
| | | - view 
| | | - Module.php 
| | - Album 
| | | - config 
| | | - src 
| | | | - Album 
| | | | | - Controller 
| | | | | | - IndexController.php 
| | | | | - Model 
| | | | | | - Bar.php 
| | | | | - Form 
| | | - view 
| | | - Module.php 
| - public 
| - vendor 
| - tests 
| | - unit 
| | | - module 
| | | | - Application 
| | | | | - src 
| | | | | | - Application 
| | | | | | | - Controller 
| | | | | | | | - IndexControllerTest.php 
| | | | | | | - Model 
| | | | | | | | - FooTest.php 
| | | | - Album 
| | | | | - src 
| | | | | | - Album 
| | | | | | | - Controller 
| | | | | | | | - IndexControllerTest.php 
| | | | | | | - Model 
| | | | | | | | - BarTest.php 
| | - functional 
| | | - features 
| - phpunit.xml 
| - phpunit-ci.xml 
| - behat.yml 

はPHPUnitのconfigsは、ニーズに応じてホワイトリスト、フィルタ、カバレッジなどを追加し、このような何か(簡単な例を見ることができます):PHPUnitの-ci.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit bootstrap="tests/unit/Bootstrap.php" colors="true" backupGlobals="false" backupStaticAttributes="false" syntaxCheck="false"> 
    <testsuites> 
     <testsuite name="sites"> 
      <directory suffix="Test.php">tests/unit</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

例:build.xmlの中

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit bootstrap="tests/unit/Bootstrap.php" colors="true" backupGlobals="false" backupStaticAttributes="false" syntaxCheck="false"> 
    <testsuites> 
     <testsuite name="sites"> 
      <directory suffix="Test.php">tests/unit</directory> 
     </testsuite> 
    </testsuites> 
    <filter> 
     <whitelist>  
      <!-- Album module --> 
      <directory suffix=".php">module/Album/src/Album/Model</directory> 
      <directory suffix=".php">module/Album/src/Album/Controller</directory> 

      <!-- Application module --> 
      <directory suffix=".php">module/Application/src/Application/Model</directory> 
      <directory suffix=".php">module/Application/src/Application/Controller</directory> 
     </whitelist> 
    </filter> 
    <logging> 
     <log type="coverage-html" target="build/coverage" charset="UTF-8" 
      yui="true" highlight="true" lowUpperBound="40" highLowerBound="80" /> 
     <log type="coverage-clover" target="build/logs/clover.xml" /> 
     <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false" /> 
    </logging> 
</phpunit> 

それは簡単です:

<target name="phpunit-ci" description="Run unit tests with config file for CI"> 
    <sequential> 

     <exec executable="${basedir}/vendor/bin/phpunit" failonerror="true"> 
      <arg value="--version" /> 
     </exec> 

     <exec executable="${basedir}/vendor/bin/phpunit" failonerror="true"> 
      <arg value="-c" /> 
      <arg path="${basedir}/phpunit-ci.xml" /> 
     </exec> 

    </sequential> 
</target> 
+0

PHPUnitの-ci.xmlの使用は何ですか? – anasaitali

関連する問題