先谢谢您的任何意见。 我刚开始从Zend框架1至ZF2切换,并通过快速启动和其他几个教程运行后,我注意到,有一个短暂的“默认”的方式来使用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
我的问题是如何使用詹金斯与ANT测试所有PHPUnit的测试套件。 我理解其背后单独测试每个模块的原因,但我怎么能正确地自动执行得到一个report.xml将回来。 如果我没有需要在PHPUnit的配置指定每个模块它甚至会更好。 或者build.xml文件。
再次感谢您的任何意见。
我忘了回答我的问题时,我想通了我道歉,我忘了...社区但每个人受益这里是我如何得到它的工作。
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>
好吧,我用下面的结构。 我的测试文件夹中的所有测试和我结构相同的方式测试,模块结构:
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可以是这个样子(简化例如,添加根据您的需要白名单,过滤器,覆盖等):
<?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>
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>
在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>