Permalink
Browse files

Fixed the way PHPUnit_Util_Configuration parses listener constructor …

…arguments

Previously, getListenerConfiguration assumed the <arguments> element
would always be the second element (index 1) because nicely formatted
XML has a DOMText node containing a newline and some space before the
arguments node. Computer-generated XML places the arguments element
immediately after the listener element, so the node would be at index 0,
causing the arguments node to not be found. Instead, it now searches
the entire listener node for argument nodes.
  • Loading branch information...
1 parent 784fa73 commit dd560a3c18ee5072507a6c3a982e53eeba8bd5b5 @austinhyde austinhyde committed Jun 22, 2012
Showing with 14 additions and 4 deletions.
  1. +4 −3 PHPUnit/Util/Configuration.php
  2. +9 −1 Tests/Util/ConfigurationTest.php
  3. +1 −0 Tests/_files/configuration.xml
@@ -344,9 +344,9 @@ public function getListenerConfiguration()
);
}
- if ($listener->childNodes->item(1) instanceof DOMElement &&
- $listener->childNodes->item(1)->tagName == 'arguments') {
- foreach ($listener->childNodes->item(1)->childNodes as $argument) {
+ foreach ($listener->childNodes as $node) {
+ if ($node instanceof DOMElement && $node->tagName == 'arguments') {
+ foreach ($node->childNodes as $argument) {
if ($argument instanceof DOMElement) {
if ($argument->tagName == 'file' ||
$argument->tagName == 'directory') {
@@ -356,6 +356,7 @@ public function getListenerConfiguration()
}
}
}
+ }
}
$result[] = array(
@@ -205,7 +205,15 @@ public function testListenerConfigurationIsReadCorrectly()
'class' => 'IncludePathListener',
'file' => __FILE__,
'arguments' => array()
- )
+ ),
+ array(
+ 'class' => 'CompactArgumentsListener',
+ 'file' => '/CompactArgumentsListener.php',
+ 'arguments' =>
+ array(
+ 0 => 42
+ ),
+ ),
),
$this->configuration->getListenerConfiguration()
);
@@ -71,6 +71,7 @@
</arguments>
</listener>
<listener class="IncludePathListener" file="ConfigurationTest.php" />
+ <listener class="CompactArgumentsListener" file="/CompactArgumentsListener.php"><arguments><integer>42</integer></arguments></listener>
</listeners>
<logging>

0 comments on commit dd560a3

Please sign in to comment.