2013-05-18 9 views
12

Vielen Dank im Voraus für Kommentare. Ich habe gerade angefangen, von Zend Framework 1 zu ZF2 zu wechseln, und nachdem ich den Schnellstart und einige andere Tutorials durchgegangen bin, habe ich gemerkt, dass es mit der "Standard" -Methode, phpunit zu verwenden, nicht so weit kommt. Entweder das oder ich bin nur verloren und verwirrt.zend framework 2 + phpunit + mehrere Module + kontinuierliche Integration

Die Ordnerstruktur für ein Standardprojekt ist

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 

Meine Frage ist, wie ich mit ANT verwenden Jenkins tun alle der phpunit Testsuiten zu testen. Ich verstehe den Grund für das Testen jedes Moduls einzeln, aber wie kann ich das richtig automatisieren, um eine report.xml zurück zu bekommen. Und es wäre noch besser, wenn ich nicht jedes Modul in einer phpunit-Konfiguration angeben müsste. oder die Datei build.xml.

Nochmals vielen Dank für Kommentare.

Antwort

4

Ich habe vergessen, meine eigene Frage zu beantworten, als ich es herausgefunden habe Ich entschuldige mich bei der Gemeinde, die ich vergessen habe ... aber für jeden Vorteil hier ist, wie ich es zur Arbeit gebracht habe.

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> 

Und das phpunit.xml für jedes Modul

<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

Nun, ich verwende die folgende Struktur. Ich habe alle Tests innerhalb Tests Ordner und ich die Tests in der gleichen Art und Weise strukturieren als Module aufgebaut sind:

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 so etwas wie dieses (vereinfachtes Beispiel aussehen kann, fügen Sie weiße Liste, Filter, Abdeckung usw. nach Ihren Bedürfnissen):

<?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> 

Beispiel 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> 
    <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> 

In build.xml ist es einfach:

+0

Was ist die Verwendung von PHPUnit-ci.xml? – anasaitali