Modify

Ticket #437 (new enhancement)

Opened 2 years ago

Last modified 5 months ago

New PHPUnit Task

Reported by: kontakt@… Owned by: mrook
Priority: minor Milestone: 2.5.0
Component: phing-tasks-phpunit Version: 2.4.0
Keywords: Cc:

Description

We were having problems in our Doctrine 2 build process using the phing 2.4 PHPUnit Task. It has several drawbacks:

  1. Can't use of the --configuration xml file. We need this for different project configuration setups when running PHPUnit.
  2. No ability to specifiy a TestSuite class. We need this because parts of our suite are haltonfailure parts are not. So we need to specify exactly which TestSuite runs and not configure some large fileset struct.
  3. No forward compability with PHPUnit. The own implementation of a the Test-Runner doesnt work with PHPUnit 3.5 and misses lots of good functionality.

Drawbacks:

I didnt bother to go the coverageMerger path or something. The information exists though and could be added. However with PHPUnit 3.5 refactoring of coverage this might become a futile task anyways.

Attachments

NativePhpunitTask.php Download (6.3 KB) - added by kontakt@… 2 years ago.

Change History

Changed 2 years ago by kontakt@…

comment:1 Changed 2 years ago by mrook

  • Priority changed from major to minor

PHPUnit 3.5 is not released yet, forward compatibility is hard as I can't read the upstream author's mind. Even though my personal preference remains hooking into the PHPUnit API (even though this changes often), I'll consider adding your task.

comment:2 Changed 2 years ago by mrook

  • Milestone changed from 2.4.1 to 2.5.0

comment:3 Changed 2 years ago by mattis@…

I have worked around this issue by creating my own PHPUnitRunnerTask that only accepts a config.xml and nothing else.

I thought this would be easier to maintain. I'll attach the task here, but it's pretty crude and just hacked together to get something to work in our environment:

<?php
require_once 'phing/Task.php';
require_once 'phing/system/io/PhingFile.php';
require_once 'PHPUnit/Framework.php';

class PHPUnitRunnerTask extends Task implements PHPUnit_Framework_TestListener {
    /**
     * @var PhingFile
     */
    private $config;
    
    private $failed = false;
    private $testFailureMessage;
    
    /**
     * @param PhingFile $config
     */
    public function setConfig(PhingFile $config) {
    	$this->config = $config;
    }
    
    public function main() {
        $configuration = PHPUnit_Util_Configuration::getInstance($this->config);
	$browsers = $configuration->getSeleniumBrowserConfiguration();
	if (!empty($browsers)) {
        	require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
            	PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
	}
		
        $testSuite = $configuration->getTestSuiteConfiguration();
        
        $runner = new PHPUnit_TextUI_TestRunner();
        $runner->doRun(
        	$testSuite, 
        	array(
        		'configuration' => $this->config,
        		'listeners' => array(
        			$this
        		),
        		'verbose' => true
        	)
        );
        
	if ($this->failed) {
            throw new BuildException($this->testFailureMessage);
        }        
    }
    
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
    	$this->failed = true;
    	$this->testFailureMessage = $e->getMessage();
    }

    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
    	$this->failed = true;
    	$this->testFailureMessage = $e->getMessage();
    }

    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}

    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}

    public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {}

    public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {}

    public function startTest(PHPUnit_Framework_Test $test) {}
    
    public function endTest(PHPUnit_Framework_Test $test, $time) {}
}

comment:4 Changed 8 months ago by Christian Weiske <cweiske@…>

I'd love to see that the Phing phpunit task accepts a configuration file path. Many projects use it, and duplicating its contents in the build.xml file is nonsense.

comment:5 Changed 5 months ago by konstantin.leboev@…

+1

View

Add a comment

Modify Ticket

Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.