Ticket #437 (new enhancement)
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:
- Can't use of the --configuration xml file. We need this for different project configuration setups when running PHPUnit.
- 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.
- 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
Change History
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: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) {}
}

