From da8c0516c909e13443a52a9bac9246560dc4cc69 Mon Sep 17 00:00:00 2001 From: Sixto Martin Date: Fri, 9 Jun 2023 03:36:15 +0200 Subject: [PATCH] Fix tests for PHP7.3 and PHP7.4 --- tests/src/OneLogin/Saml2/MetadataTest.php | 10 ++++++---- tests/src/OneLogin/Saml2/SettingsTest.php | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/src/OneLogin/Saml2/MetadataTest.php b/tests/src/OneLogin/Saml2/MetadataTest.php index 3a93e3eb..290ff9ff 100644 --- a/tests/src/OneLogin/Saml2/MetadataTest.php +++ b/tests/src/OneLogin/Saml2/MetadataTest.php @@ -165,8 +165,9 @@ public function testSignMetadata() try { $signedMetadata2 = Metadata::signMetadata('', $key, $cert); $this->fail('Exception was not raised'); - } catch (\Error $e) { - $this->assertStringContainsString('Argument #1 ($source) must not be empty', $e->getMessage()); + } catch (\Error | \Exception $e) { + $expectedErrors = array('DOMDocument::loadXML(): Argument #1 ($source) must not be empty', 'DOMDocument::loadXML(): Empty string supplied as input'); + $this->assertTrue(in_array($e->getMessage(), $expectedErrors)); } } @@ -261,8 +262,9 @@ public function testAddX509KeyDescriptors() try { $signedMetadata2 = Metadata::addX509KeyDescriptors('', $cert); $this->fail('Exception was not raised'); - } catch (\Error $e) { - $this->assertStringContainsString('Argument #1 ($source) must not be empty', $e->getMessage()); + } catch (\Error | \Exception $e) { + $expectedErrors = array('DOMDocument::loadXML(): Argument #1 ($source) must not be empty', 'Error parsing metadata. DOMDocument::loadXML(): Empty string supplied as input'); + $this->assertTrue(in_array($e->getMessage(), $expectedErrors)); } libxml_use_internal_errors(true); diff --git a/tests/src/OneLogin/Saml2/SettingsTest.php b/tests/src/OneLogin/Saml2/SettingsTest.php index 87708629..ca0ed7c4 100644 --- a/tests/src/OneLogin/Saml2/SettingsTest.php +++ b/tests/src/OneLogin/Saml2/SettingsTest.php @@ -831,8 +831,9 @@ public function testValidateMetadataNoXML() try { $errors = $settings->validateMetadata($metadata); $this->fail('Exception was not raised'); - } catch (\Error $e) { - $this->assertStringContainsString('Argument #1 ($source) must not be empty', $e->getMessage()); + } catch (\Error | \Exception $e) { + $expectedErrors = array('DOMDocument::loadXML(): Argument #1 ($source) must not be empty', 'DOMDocument::loadXML(): Empty string supplied as input'); + $this->assertTrue(in_array($e->getMessage(), $expectedErrors)); } $metadata = '';