Skip to content

Commit 54dac91

Browse files
committed
Merge pull request #23 from hordijk/handleNullForGetFormatedXml
Add support to invoke getLastRequest without throwing an InvalidArgumentException if the request is not executed - Fix for #22
1 parent 78f7ce2 commit 54dac91

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Utils.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ class Utils
99
* @throws \InvalidArgumentException
1010
* @param string $string
1111
* @param bool $asDomDocument
12-
* @return \DOMDocument|null
12+
* @return \DOMDocument|string|null
1313
*/
1414
public static function getFormatedXml($string, $asDomDocument = false)
1515
{
16-
$domDocument = self::getDOMDocument($string);
17-
return $asDomDocument ? $domDocument : $domDocument->saveXML();
16+
if (!is_null($string)) {
17+
$domDocument = self::getDOMDocument($string);
18+
return $asDomDocument ? $domDocument : $domDocument->saveXML();
19+
}
20+
return null;
1821
}
1922
/**
2023
* @param string $string

tests/UtilsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ public function testGetFormatedXmlInvalidXmlAsDomDocument()
4141
{
4242
Utils::getFormatedXml('<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:img="http://ws.estesexpress.com/imageview" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://ws.estesexpress.com/imageview" xml:lang="en"><root>', true);
4343
}
44+
/**
45+
*
46+
*/
47+
public function testGetFormatedXmlNullAsString()
48+
{
49+
$this->assertNull(Utils::getFormatedXml(null));
50+
}
51+
/**
52+
*
53+
*/
54+
public function testGetFormatedXmlNullAsDomDocument()
55+
{
56+
$this->assertNull(Utils::getFormatedXml(null, true));
57+
}
4458
/**
4559
*
4660
*/

0 commit comments

Comments
 (0)