Phing and phpunit + bootstrap

How to run PHPUnit test suite with bootstrap file with phing?

My application structure:

application/ library/ tests/ application/ library/ bootstrap.php phpunit.xml build.xml 

phpunit.xml:

 <phpunit bootstrap="./bootstrap.php" colors="true"> <testsuite name="Application Test Suite"> <directory>./</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">../library/</directory> <directory suffix=".php">../application/</directory> <exclude> <directory suffix=".phtml">../application/</directory> </exclude> </whitelist> </filter> </phpunit> 

then

 cd /path/to/app/tests/ phpunit #all test passed 

But how do I run tests from /path/to/app/ dir? The problem is that bootstrap.php depends on the relative paths to the library and the application.

If I ran phpunit --configuration tests/phpunit.xml /tests , I got a bunch of files that did not find errors.

How to write build.xml file for phing to run tests in the same way phpunit.xml ?

+4
source share
2 answers

I think the best way is to create a little PHP Script to initialize your unit tests, and I do the following:

In my phpunit.xml / bootstrap = "./initalize.php"

initalize.php

 define('BASE_PATH', realpath(dirname(__FILE__) . '/../')); define('APPLICATION_PATH', BASE_PATH . '/application'); // Include path set_include_path( '.' . PATH_SEPARATOR . BASE_PATH . '/library' . PATH_SEPARATOR . get_include_path() ); // Define application environment define('APPLICATION_ENV', 'testing'); require_once 'BaseTest.php'; 

BaseTest.php

 abstract class BaseTest extends Zend_Test_PHPUnit_ControllerTestCase { /** * Application * * @var Zend_Application */ public $application; /** * SetUp for Unit tests * * @return void */ public function setUp() { $session = new Zend_Session_Namespace(); $this->application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $this->bootstrap = array($this, 'appBootstrap'); Zend_Session::$_unitTestEnabled; parent::setUp(); } /** * Bootstrap * * @return void */ public function appBootstrap() { $this->application->bootstrap(); } } 

All my unit tests extend the BaseTest class, it works like a charm.

+4
source

When you use PHPUnit tasks in Phing, you can include your bootstrap file as follows:

 <target name="test"> <phpunit bootstrap="tests/bootstrap.php"> <formatter type="summary" usefile="false" /> <batchtest> <fileset dir="tests"> <include name="**/*Test.php"/> </fileset> </batchtest> </phpunit> </target> 
+3
source

All Articles