zend framework 2 + phpunit + multiple modules + continuous integration
I forgot to answer my own question when I figured it out I apologize to the community that I forgot... but for everyones benefit here is how I got it to work.
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>
And the phpunit.xml for each module
<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>
Well, I use the following structure. I have all tests inside tests folder and I structure the tests in the same way as modules are structured:
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 can look something like this (simplified example, add whitelist, filters, coverage etc according to your needs):
<?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>
Example of 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 it's easy:
<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>