Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant zend框架2+;phpunit+;多模块&x2B;连续积分_Ant_Jenkins_Phpunit_Zend Framework2 - Fatal编程技术网

Ant zend框架2+;phpunit+;多模块&x2B;连续积分

Ant zend框架2+;phpunit+;多模块&x2B;连续积分,ant,jenkins,phpunit,zend-framework2,Ant,Jenkins,Phpunit,Zend Framework2,提前感谢您的评论。我刚刚开始从Zend Framework 1切换到ZF2,在运行了quick start和其他几个教程之后,我注意到使用phpunit的“默认”方式有一个缺点。不是这样,就是我迷失了方向 默认项目的文件夹结构为 Project | - config | | - autoload | | | - global.php | | | - local.php.dist | | - application.config.php | - data | - module | | - Appl

提前感谢您的评论。我刚刚开始从Zend Framework 1切换到ZF2,在运行了quick start和其他几个教程之后,我注意到使用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
我的问题是如何使用Jenkins和ANT来测试所有phpunit测试套件。我理解单独测试每个模块背后的原因,但我如何能够正确地自动化这些模块以获得一个report.xml。如果我不需要在phpunit配置中指定每个模块,那就更好了。或者build.xml


再次感谢您的评论。

好吧,我使用以下结构。我将所有测试都放在测试文件夹中,并且我以与模块结构相同的方式构造测试:

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配置可以如下所示(简化示例,根据需要添加白名单、过滤器、覆盖范围等):


测试/单元
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>

测试/单元
模块/Album/src/Album/Model
模块/Album/src/Album/Controller
模块/应用程序/src/应用程序/模型
模块/应用程序/src/应用程序/控制器
在build.xml中,很容易:

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

我发现自己的问题时忘了回答,我向社区道歉,我忘了。。。但对每个人来说,这是我成功的原因

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


./
../../../vendor/
./
../Module.php
<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 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>