I have a zend framework 2 project and i am trying to set up my jenkins so that unit tests can be executed. Jenkins is running on ubuntu and i am developing under Windows 7 with PHPStorm.
build.xml
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true">
<arg value="${basedir}/module/Addressbook/test"/>
</exec>
</target>
Folder structure:
- project
- module
- Addressbook
- test
- AddressbookTest
- Controller
- AddressbookControllerTest.php
- Boostrap.php
- phpunit.xml.dist
- TestConfig.php
- Controller
- AddressbookTest
- build.xml
- module
Jenkins Output:
phpunit: [exec] PHPUnit 3.7.13 by Sebastian Bergmann. [exec] [exec] PHP Fatal error: Class 'AddressbookTest\Bootstrap' not found in /var/lib/jenkins/workspace/Test/src/module/Addressbook/test/AddressbookTest/Controller/AddressbookControllerTest.php on line 28
PHPStorm on my local machine does this when running 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?
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: