Permalink
Browse files

make class of a test suite customizable

When using phpunit with an XML configuration file, every testsuite element is by default mapped to an instance of class PHPUnit_Framework_TestSuite.

If the testsuite element contains a @class attribute, the actual class can be overridden.

Example:

<phpunit>
    <testsuites>
        <testsuite name="My Tests" class="MyTestSuite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>
  • Loading branch information...
1 parent 1c3ade4 commit 6bc9017a503168ea4db9bacc93f861e4f8fa96ac Marcus Lunzenauer committed Dec 15, 2011
Showing with 20 additions and 7 deletions.
  1. +1 −1 PHPUnit/TextUI/Command.php
  2. +19 −6 PHPUnit/Util/Configuration.php
@@ -663,7 +663,7 @@ class_exists('PHPUnit_Extensions_SeleniumTestCase')) {
}
if (!isset($this->arguments['test'])) {
- $testSuite = $configuration->getTestSuiteConfiguration();
+ $testSuite = $configuration->getTestSuiteConfiguration($this->arguments['loader'] ?: NULL);
if ($testSuite !== NULL) {
$this->arguments['test'] = $testSuite;
@@ -753,27 +753,33 @@ public function getSeleniumBrowserConfiguration()
/**
* Returns the test suite configuration.
*
+ * @param PHPUnit_Runner_TestSuiteLoader $loader
+ *
* @return PHPUnit_Framework_TestSuite
* @since Method available since Release 3.2.1
*/
- public function getTestSuiteConfiguration()
+ public function getTestSuiteConfiguration($loader = NULL)
{
+ if ($loader === NULL) {
+ $loader = new PHPUnit_Runner_StandardTestSuiteLoader;
+ }
+
$testSuiteNodes = $this->xpath->query('testsuites/testsuite');
if ($testSuiteNodes->length == 0) {
$testSuiteNodes = $this->xpath->query('testsuite');
}
if ($testSuiteNodes->length == 1) {
- return $this->getTestSuite($testSuiteNodes->item(0));
+ return $this->getTestSuite($testSuiteNodes->item(0), $loader);
}
if ($testSuiteNodes->length > 1) {
$suite = new PHPUnit_Framework_TestSuite;
foreach ($testSuiteNodes as $testSuiteNode) {
$suite->addTestSuite(
- $this->getTestSuite($testSuiteNode)
+ $this->getTestSuite($testSuiteNode, $loader)
);
}
@@ -783,17 +789,24 @@ public function getTestSuiteConfiguration()
/**
* @param DOMElement $testSuiteNode
+ * @param PHPUnit_Runner_TestSuiteLoader $loader
* @return PHPUnit_Framework_TestSuite
* @since Method available since Release 3.4.0
*/
- protected function getTestSuite(DOMElement $testSuiteNode)
+ protected function getTestSuite(DOMElement $testSuiteNode, $loader)
{
+ $class = "PHPUnit_Framework_TestSuite";
+ if ($testSuiteNode->hasAttribute('class')) {
+ $class = (string)$testSuiteNode->getAttribute('class');
+ $loader->load($class);
+ }
+
if ($testSuiteNode->hasAttribute('name')) {
- $suite = new PHPUnit_Framework_TestSuite(
+ $suite = new $class(
(string)$testSuiteNode->getAttribute('name')
);
} else {
- $suite = new PHPUnit_Framework_TestSuite;
+ $suite = new $class();
}
$exclude = array();

0 comments on commit 6bc9017

Please sign in to comment.