Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #680 from tobyS/config_xinclude_3_7

  • Loading branch information...
commit 158aef2e833e32b205ce28eccab3c493a25e52fd 2 parents 8c0ffdd + b825d33
@sebastianbergmann authored
View
2  PHPUnit/Util/Configuration.php
@@ -189,7 +189,7 @@ class PHPUnit_Util_Configuration
protected function __construct($filename)
{
$this->filename = $filename;
- $this->document = PHPUnit_Util_XML::loadFile($filename);
+ $this->document = PHPUnit_Util_XML::loadFile($filename, FALSE, TRUE);
$this->xpath = new DOMXPath($this->document);
}
View
23 PHPUnit/Util/XML.php
@@ -78,10 +78,11 @@ public static function prepareString($string)
*
* @param string $filename
* @param boolean $isHtml
+ * @param boolean $xinclude
* @return DOMDocument
* @since Method available since Release 3.3.0
*/
- public static function loadFile($filename, $isHtml = FALSE)
+ public static function loadFile($filename, $isHtml = FALSE, $xinclude = FALSE)
{
$reporting = error_reporting(0);
$contents = file_get_contents($filename);
@@ -96,7 +97,7 @@ public static function loadFile($filename, $isHtml = FALSE)
);
}
- return self::load($contents, $isHtml, $filename);
+ return self::load($contents, $isHtml, $filename, $xinclude);
}
/**
@@ -105,7 +106,9 @@ public static function loadFile($filename, $isHtml = FALSE)
*
* If $actual is already a DOMDocument, it is returned with
* no changes. Otherwise, $actual is loaded into a new DOMDocument
- * as either HTML or XML, depending on the value of $isHtml.
+ * as either HTML or XML, depending on the value of $isHtml. If $isHtml is
+ * false and $xinclude is true, xinclude is performed on the loaded
+ * DOMDocument.
*
* Note: prior to PHPUnit 3.3.0, this method loaded a file and
* not a string as it currently does. To load a file into a
@@ -114,18 +117,21 @@ public static function loadFile($filename, $isHtml = FALSE)
* @param string|DOMDocument $actual
* @param boolean $isHtml
* @param string $filename
+ * @param boolean $xinclude
* @return DOMDocument
* @since Method available since Release 3.3.0
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
+ * @author Tobias Schlitt <toby@php.net>
*/
- public static function load($actual, $isHtml = FALSE, $filename = '')
+ public static function load($actual, $isHtml = FALSE, $filename = '', $xinclude = FALSE)
{
if ($actual instanceof DOMDocument) {
return $actual;
}
$document = new DOMDocument;
+
$internal = libxml_use_internal_errors(TRUE);
$message = '';
$reporting = error_reporting(0);
@@ -136,6 +142,15 @@ public static function load($actual, $isHtml = FALSE, $filename = '')
$loaded = $document->loadXML($actual);
}
+ if ('' !== $filename) {
+ // Necessary for xinclude
+ $document->documentURI = $filename;
+ }
+
+ if (!$isHtml && $xinclude) {
+ $document->xinclude();
+ }
+
foreach (libxml_get_errors() as $error) {
$message .= $error->message;
}
View
55 Tests/Util/ConfigurationTest.php
@@ -332,4 +332,59 @@ public function testSeleniumBrowserConfigurationIsReadCorrectly()
$this->configuration->getSeleniumBrowserConfiguration()
);
}
+
+ public function testXincludeInConfiguration()
+ {
+ $configurationWithXinclude = PHPUnit_Util_Configuration::getInstance(
+ dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'configuration_xinclude.xml'
+ );
+
+ $this->assertConfigurationEquals(
+ $this->configuration,
+ $configurationWithXinclude
+ );
+ }
+
+ /**
+ * Asserts that the values in $actualConfiguration equal $expectedConfiguration.
+ *
+ * @param PHPUnit_Util_Configuration $expectedConfiguration
+ * @param PHPUnit_Util_Configuration $actualConfiguration
+ * @return void
+ */
+ protected function assertConfigurationEquals( PHPUnit_Util_Configuration $expectedConfiguration, PHPUnit_Util_Configuration $actualConfiguration )
+ {
+ $this->assertEquals(
+ $expectedConfiguration->getFilterConfiguration(),
+ $actualConfiguration->getFilterConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getGroupConfiguration(),
+ $actualConfiguration->getGroupConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getListenerConfiguration(),
+ $actualConfiguration->getListenerConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getLoggingConfiguration(),
+ $actualConfiguration->getLoggingConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getPHPConfiguration(),
+ $actualConfiguration->getPHPConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getPHPUnitConfiguration(),
+ $actualConfiguration->getPHPUnitConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getSeleniumBrowserConfiguration(),
+ $actualConfiguration->getSeleniumBrowserConfiguration()
+ );
+ $this->assertEquals(
+ $expectedConfiguration->getTestSuiteConfiguration(),
+ $actualConfiguration->getTestSuiteConfiguration()
+ );
+ }
}
View
68 Tests/_files/configuration_xinclude.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+<phpunit backupGlobals="true"
+ backupStaticAttributes="false"
+ bootstrap="/path/to/bootstrap.php"
+ cacheTokens="true"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ forceCoversAnnotation="false"
+ mapTestClassNameToCoveredClassName="false"
+ printerClass="PHPUnit_TextUI_ResultPrinter"
+ stopOnFailure="false"
+ testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
+ timeoutForSmallTests="1"
+ timeoutForMediumTests="10"
+ timeoutForLargeTests="60"
+ strict="false"
+ verbose="false">
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/testsuites)" />
+
+ <groups>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/groups/*)" />
+ </groups>
+
+
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/filter)" />
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/listeners)" />
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/logging)" />
+
+ <php>
+ <includePath>.</includePath>
+ <includePath>/path/to/lib</includePath>
+ <ini name="foo" value="bar"/>
+ <const name="FOO" value="false"/>
+ <const name="BAR" value="true"/>
+ <var name="foo" value="false"/>
+ <env name="foo" value="true"/>
+ <post name="foo" value="bar"/>
+ <get name="foo" value="bar"/>
+ <cookie name="foo" value="bar"/>
+ <server name="foo" value="bar"/>
+ <files name="foo" value="bar"/>
+ <request name="foo" value="bar"/>
+ </php>
+
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="configuration.xml"
+ parse="xml"
+ xpointer="xpointer(/phpunit/selenium)" />
+</phpunit>
+
Please sign in to comment.
Something went wrong with that request. Please try again.