1

我有一个 zend 框架 2 项目,我正在尝试设置我的 jenkins 以便可以执行单元测试。Jenkins 在 ubuntu 上运行,我正在使用 PHPStorm 在 Windows 7 下开发。

构建.xml

<target name="phpunit" description="Run unit tests with PHPUnit">
    <exec executable="phpunit" failonerror="true">
        <arg value="${basedir}/module/Addressbook/test"/>
    </exec>
</target>

文件夹结构:

  • 项目
    • 模块
      • 地址簿
      • 测试
        • 通讯录测试
          • 控制器
            • 地址簿控制器测试.php
          • Boostrap.php
          • phpunit.xml.dist
          • 测试配置.php
    • 构建.xml

詹金斯输出:

php单元:
     [执行] Sebastian Bergmann 的 PHPUnit 3.7.13。
     [执行]
     [exec] PHP 致命错误:在第 28 行的 /var/lib/jenkins/workspace/Test/src/module/Addressbook/test/AddressbookTest/Controller/AddressbookControllerTest.php 中找不到类 'AddressbookTest\Bootstrap'

我本地机器上的 PHPStorm 在运行 phpunit.xml.dist 时会执行此操作

D:\Zend\ZendServer\bin\php.exe -d auto_prepend_file=D:/Zend/Apache2/htdocs/demoshop/vendor/autoload.php C:\Users\ChristianB\AppData\Local\Temp\ide-phpunit.php --configuration D:/Zend/Apache2/htdocs/demoshop/module/Addressbook/test/phpunit.xml.dist

How can i use that for jenkins?

4

1 回答 1

0

It looks like your include path isn't setup correctly, I wouldn't use exec directly with PHPUNIT when there's better options.

You should look into using PHING tasks with Jenkins, they work excellent together.

You then setup Jenking to trigger your PHING target to run the unit tests for you via the PHPUNIT task, an example phing target for PHPUNIT:

<target name="phpunit">
    <phpunit bootstrap="${srcdir}/tests/bootstrap.php">
        <formatter todir="${builddir}/reports" type="xml"/>
        <batchtest>
            <fileset dir="${srcdir}/tests">
                <include name="**/*Test*.php"/>
                <exclude name="**/Abstract*.php"/>
                <exclude name="${srcdir}/vendor/**"/>
            </fileset>
        </batchtest>
    </phpunit>
    <!-- 
        Generate a report from the XML data created.. 
        note: error when using format="frames"
    --> 
    <phpunitreport infile="${builddir}/reports/testsuites.xml" 
        format="noframes" 
        todir="${builddir}/reports/tests"
    />

</target>
于 2013-01-28T09:00:22.153 回答