From c1bf461413f64bb1870e12b19d4541ea4e27b099 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 25 Jul 2014 21:08:03 +0200 Subject: [PATCH 1/5] Fixed XML::load() does not report libxml errors on Windows. --- src/Util/XML.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Util/XML.php b/src/Util/XML.php index e4ac534ddb1..8f7ee7b4ac5 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -157,14 +157,14 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude } foreach (libxml_get_errors() as $error) { - $message .= $error->message; + $message .= "\n" . $error->message; } libxml_use_internal_errors($internal); error_reporting($reporting); - if ($loaded === false) { - if ($filename != '') { + if ($loaded === false || $message !== '') { + if ($filename !== '') { throw new PHPUnit_Framework_Exception( sprintf( 'Could not load "%s".%s', From b93090b7807cfe24054fd345a8f83b298fa16359 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 25 Jul 2014 21:10:52 +0200 Subject: [PATCH 2/5] Fixed XML::load() fails to load relative XInclude paths on Windows. --- src/Util/XML.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Util/XML.php b/src/Util/XML.php index 8f7ee7b4ac5..97c68c66fde 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -135,23 +135,29 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude return $actual; } + // Required for XInclude on Windows. + if ($xinclude) { + $cwd = getcwd(); + chdir(dirname($filename)); + } + $document = new DOMDocument; $internal = libxml_use_internal_errors(true); $message = ''; $reporting = error_reporting(0); + if ('' !== $filename) { + // Necessary for xinclude + $document->documentURI = $filename; + } + if ($isHtml) { $loaded = $document->loadHTML($actual); } else { $loaded = $document->loadXML($actual); } - if ('' !== $filename) { - // Necessary for xinclude - $document->documentURI = $filename; - } - if (!$isHtml && $xinclude) { $document->xinclude(); } @@ -163,6 +169,10 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude libxml_use_internal_errors($internal); error_reporting($reporting); + if ($xinclude) { + chdir($cwd); + } + if ($loaded === false || $message !== '') { if ($filename !== '') { throw new PHPUnit_Framework_Exception( From de80d073253511bcbaca7e9caddba917f724b775 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 25 Jul 2014 21:29:59 +0200 Subject: [PATCH 3/5] Exclude system temp directory in stack traces on Windows. PHPUnit_Util_PHP_Windows writes the process isolation script template into the Windows TEMP directory and loads the script by including the file, which causes an extraneous last stack frame in all test results on Windows. --- src/Util/Blacklist.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Util/Blacklist.php b/src/Util/Blacklist.php index 40f978812e6..554edbc694e 100644 --- a/src/Util/Blacklist.php +++ b/src/Util/Blacklist.php @@ -136,6 +136,13 @@ private function initialize() self::$directories[] = $directory; } + + // Process isolation workaround on Windows. + // @see PHPUnit_Util_PHP::factory() + // @see PHPUnit_Util_PHP_Windows::process() + if (DIRECTORY_SEPARATOR === '\\') { + self::$directories[] = sys_get_temp_dir(); + } } } } From 6c1e0cbd4abfb28e7480e2f40830be4d3b0d3309 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 25 Jul 2014 21:38:40 +0200 Subject: [PATCH 4/5] Fixed PHPT file path expectations fail on Windows. --- tests/Regression/578.phpt | 6 +++--- tests/Regression/GitHub/74.phpt | 2 +- tests/TextUI/custom-printer-debug.phpt | 2 +- tests/TextUI/custom-printer-verbose.phpt | 2 +- tests/TextUI/dataprovider-log-xml-isolation.phpt | 2 +- tests/TextUI/dataprovider-log-xml.phpt | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Regression/578.phpt b/tests/Regression/578.phpt index dfbf855b395..4a4d3e07fbc 100644 --- a/tests/Regression/578.phpt +++ b/tests/Regression/578.phpt @@ -21,17 +21,17 @@ There were 3 errors: 1) Issue578Test::testNoticesDoublePrintStackTrace Invalid error type specified -%s/Issue578Test.php:%i +%sIssue578Test.php:%i 2) Issue578Test::testWarningsDoublePrintStackTrace Invalid error type specified -%s/Issue578Test.php:%i +%sIssue578Test.php:%i 3) Issue578Test::testUnexpectedExceptionsPrintsCorrectly Exception: Double printed exception -%s/Issue578Test.php:%i +%sIssue578Test.php:%i FAILURES! Tests: 3, Assertions: 0, Errors: 3. diff --git a/tests/Regression/GitHub/74.phpt b/tests/Regression/GitHub/74.phpt index 79b33a4a1f3..7005b41f4eb 100644 --- a/tests/Regression/GitHub/74.phpt +++ b/tests/Regression/GitHub/74.phpt @@ -22,7 +22,7 @@ There was 1 error: 1) Issue74Test::testCreateAndThrowNewExceptionInProcessIsolation NewException: Testing GH-74 -%s/tests/Regression/GitHub/74/Issue74Test.php:7 +%sIssue74Test.php:7 FAILURES! Tests: 1, Assertions: 0, Errors: 1. diff --git a/tests/TextUI/custom-printer-debug.phpt b/tests/TextUI/custom-printer-debug.phpt index a73d0ac9b5f..fcbd3a4705a 100644 --- a/tests/TextUI/custom-printer-debug.phpt +++ b/tests/TextUI/custom-printer-debug.phpt @@ -14,7 +14,7 @@ PHPUnit_TextUI_Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann. -Configuration read from %s/configuration.custom-printer.xml +Configuration read from %sconfiguration.custom-printer.xml Starting test 'BankAccountTest::testBalanceIsInitiallyZero'. diff --git a/tests/TextUI/custom-printer-verbose.phpt b/tests/TextUI/custom-printer-verbose.phpt index 4528e397d6f..fc5f9f481b8 100644 --- a/tests/TextUI/custom-printer-verbose.phpt +++ b/tests/TextUI/custom-printer-verbose.phpt @@ -14,7 +14,7 @@ PHPUnit_TextUI_Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann. -Configuration read from %s/configuration.custom-printer.xml +Configuration read from %sconfiguration.custom-printer.xml I diff --git a/tests/TextUI/dataprovider-log-xml-isolation.phpt b/tests/TextUI/dataprovider-log-xml-isolation.phpt index bb8c55f1499..5154f422607 100644 --- a/tests/TextUI/dataprovider-log-xml-isolation.phpt +++ b/tests/TextUI/dataprovider-log-xml-isolation.phpt @@ -17,7 +17,7 @@ PHPUnit %s by Sebastian Bergmann. ..F. - + diff --git a/tests/TextUI/dataprovider-log-xml.phpt b/tests/TextUI/dataprovider-log-xml.phpt index fa7287c3bb0..9854e2f16a5 100644 --- a/tests/TextUI/dataprovider-log-xml.phpt +++ b/tests/TextUI/dataprovider-log-xml.phpt @@ -16,7 +16,7 @@ PHPUnit %s by Sebastian Bergmann. ..F. - + From 59a3263ef24e14c7920247344beaf115d20626e5 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 25 Jul 2014 23:32:55 +0200 Subject: [PATCH 5/5] Include process isolation file prefix to avoid false-positive matches. --- src/Util/Blacklist.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Util/Blacklist.php b/src/Util/Blacklist.php index 554edbc694e..d767d81bfbe 100644 --- a/src/Util/Blacklist.php +++ b/src/Util/Blacklist.php @@ -137,11 +137,13 @@ private function initialize() self::$directories[] = $directory; } - // Process isolation workaround on Windows. + // Hide process isolation workaround on Windows. // @see PHPUnit_Util_PHP::factory() // @see PHPUnit_Util_PHP_Windows::process() if (DIRECTORY_SEPARATOR === '\\') { - self::$directories[] = sys_get_temp_dir(); + // tempnam() prefix is limited to first 3 chars. + // @see http://php.net/manual/en/function.tempnam.php + self::$directories[] = sys_get_temp_dir() . '\\PHP'; } } }