From 9e2aa97f0d51f114983666f5aa362426d53e004a Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 13 Jul 2020 00:27:19 +0200 Subject: [PATCH 1/3] Fix PHPUnit 8.5 deprecations. --- Tests/Resource/DirectoryResourceTest.php | 2 +- Tests/Resource/FileResourceTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Resource/DirectoryResourceTest.php b/Tests/Resource/DirectoryResourceTest.php index 40b179010..700df4565 100644 --- a/Tests/Resource/DirectoryResourceTest.php +++ b/Tests/Resource/DirectoryResourceTest.php @@ -66,7 +66,7 @@ public function testGetPattern() public function testResourceDoesNotExist() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The directory ".*" does not exist./'); + $this->expectExceptionMessageMatches('/The directory ".*" does not exist./'); new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999)); } diff --git a/Tests/Resource/FileResourceTest.php b/Tests/Resource/FileResourceTest.php index 968c7e926..5b789700a 100644 --- a/Tests/Resource/FileResourceTest.php +++ b/Tests/Resource/FileResourceTest.php @@ -56,7 +56,7 @@ public function testToString() public function testResourceDoesNotExist() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The file ".*" does not exist./'); + $this->expectExceptionMessageMatches('/The file ".*" does not exist./'); new FileResource('/____foo/foobar'.mt_rand(1, 999999)); } From 9edcb27918e62efca5cdfdaf325b1d849b352408 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 8 Aug 2020 16:41:28 +0200 Subject: [PATCH 2/3] Modernized deprecated PHPUnit assertion calls --- Tests/Util/XmlUtilsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Util/XmlUtilsTest.php b/Tests/Util/XmlUtilsTest.php index 2aecdf825..ffd017267 100644 --- a/Tests/Util/XmlUtilsTest.php +++ b/Tests/Util/XmlUtilsTest.php @@ -81,7 +81,7 @@ public function testLoadFile() XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']); $this->fail(); } catch (\InvalidArgumentException $e) { - $this->assertRegExp('/The XML file ".+" is not valid\./', $e->getMessage()); + $this->assertMatchesRegularExpression('/The XML file ".+" is not valid\./', $e->getMessage()); } $this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate'])); From 55c9f1b8e1054435a2fbb444843d276721b6ce79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 7 Aug 2020 11:40:57 +0200 Subject: [PATCH 3/3] Fix deprecated libxml_disable_entity_loader --- Tests/Util/XmlUtilsTest.php | 15 +++++++++------ Util/XmlUtils.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Tests/Util/XmlUtilsTest.php b/Tests/Util/XmlUtilsTest.php index 2aecdf825..c964c525e 100644 --- a/Tests/Util/XmlUtilsTest.php +++ b/Tests/Util/XmlUtilsTest.php @@ -199,7 +199,9 @@ public function testLoadEmptyXmlFile() // test for issue https://github.com/symfony/symfony/issues/9731 public function testLoadWrongEmptyXMLWithErrorHandler() { - $originalDisableEntities = libxml_disable_entity_loader(false); + if (LIBXML_VERSION < 20900) { + $originalDisableEntities = libxml_disable_entity_loader(false); + } $errorReporting = error_reporting(-1); set_error_handler(function ($errno, $errstr) { @@ -219,12 +221,13 @@ public function testLoadWrongEmptyXMLWithErrorHandler() error_reporting($errorReporting); } - $disableEntities = libxml_disable_entity_loader(true); - libxml_disable_entity_loader($disableEntities); - - libxml_disable_entity_loader($originalDisableEntities); + if (LIBXML_VERSION < 20900) { + $disableEntities = libxml_disable_entity_loader(true); + libxml_disable_entity_loader($disableEntities); - $this->assertFalse($disableEntities); + libxml_disable_entity_loader($originalDisableEntities); + $this->assertFalse($disableEntities); + } // should not throw an exception XmlUtils::loadFile(__DIR__.'/../Fixtures/Util/valid.xml', __DIR__.'/../Fixtures/Util/schema.xsd'); diff --git a/Util/XmlUtils.php b/Util/XmlUtils.php index c925f315e..203741ad1 100644 --- a/Util/XmlUtils.php +++ b/Util/XmlUtils.php @@ -51,13 +51,17 @@ public static function parse($content, $schemaOrCallable = null) } $internalErrors = libxml_use_internal_errors(true); - $disableEntities = libxml_disable_entity_loader(true); + if (LIBXML_VERSION < 20900) { + $disableEntities = libxml_disable_entity_loader(true); + } libxml_clear_errors(); $dom = new \DOMDocument(); $dom->validateOnParse = true; if (!$dom->loadXML($content, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - libxml_disable_entity_loader($disableEntities); + if (LIBXML_VERSION < 20900) { + libxml_disable_entity_loader($disableEntities); + } throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors))); } @@ -65,7 +69,9 @@ public static function parse($content, $schemaOrCallable = null) $dom->normalizeDocument(); libxml_use_internal_errors($internalErrors); - libxml_disable_entity_loader($disableEntities); + if (LIBXML_VERSION < 20900) { + libxml_disable_entity_loader($disableEntities); + } foreach ($dom->childNodes as $child) { if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) {