diff --git a/src/BeSimple/SoapCommon/Converter/DateTimeTypeConverter.php b/src/BeSimple/SoapCommon/Converter/DateTimeTypeConverter.php index 6446e35..6b0a729 100644 --- a/src/BeSimple/SoapCommon/Converter/DateTimeTypeConverter.php +++ b/src/BeSimple/SoapCommon/Converter/DateTimeTypeConverter.php @@ -32,6 +32,10 @@ class DateTimeTypeConverter implements TypeConverterInterface $doc = new \DOMDocument(); $doc->loadXML($data); + if ('' === $doc->textContent) { + return null; + } + return new \DateTime($doc->textContent); } @@ -39,4 +43,5 @@ class DateTimeTypeConverter implements TypeConverterInterface { return sprintf('<%1$s>%2$s', $this->getTypeName(), $data->format('Y-m-d\TH:i:sP')); } -} \ No newline at end of file +} + diff --git a/src/BeSimple/SoapCommon/Converter/DateTypeConverter.php b/src/BeSimple/SoapCommon/Converter/DateTypeConverter.php index 4e21425..11d5ad2 100644 --- a/src/BeSimple/SoapCommon/Converter/DateTypeConverter.php +++ b/src/BeSimple/SoapCommon/Converter/DateTypeConverter.php @@ -32,6 +32,10 @@ class DateTypeConverter implements TypeConverterInterface $doc = new \DOMDocument(); $doc->loadXML($data); + if ('' === $doc->textContent) { + return null; + } + return new \DateTime($doc->textContent); } @@ -40,3 +44,4 @@ class DateTypeConverter implements TypeConverterInterface return sprintf('<%1$s>%2$s', $this->getTypeName(), $data->format('Y-m-d')); } } + diff --git a/tests/BeSimple/Tests/SoapCommon/Converter/DateTimeTypeConverterTest.php b/tests/BeSimple/Tests/SoapCommon/Converter/DateTimeTypeConverterTest.php index d7913f5..9546722 100644 --- a/tests/BeSimple/Tests/SoapCommon/Converter/DateTimeTypeConverterTest.php +++ b/tests/BeSimple/Tests/SoapCommon/Converter/DateTimeTypeConverterTest.php @@ -40,4 +40,15 @@ class DateTimeTypeConverterTest extends \PHPUnit_Framework_TestCase $this->assertEquals('2002-10-10T12:00:00-05:00', $dateXml); } -} \ No newline at end of file + + public function testConvertNullDateTimeXmlToPhp() + { + $converter = new DateTimeTypeConverter(); + + $dateXml = ''; + $date = $converter->convertXmlToPhp($dateXml); + + $this->assertNull($date); + } +} + diff --git a/tests/BeSimple/Tests/SoapCommon/Converter/DateTypeConverterTest.php b/tests/BeSimple/Tests/SoapCommon/Converter/DateTypeConverterTest.php index 6e164cb..48bddcc 100644 --- a/tests/BeSimple/Tests/SoapCommon/Converter/DateTypeConverterTest.php +++ b/tests/BeSimple/Tests/SoapCommon/Converter/DateTypeConverterTest.php @@ -38,4 +38,15 @@ class DateTypeConverterTest extends \PHPUnit_Framework_TestCase $this->assertEquals('2002-10-10', $dateXml); } -} \ No newline at end of file + + public function testConvertNullDateTimeXmlToPhp() + { + $converter = new DateTypeConverter(); + + $dateXml = ''; + $date = $converter->convertXmlToPhp($dateXml); + + $this->assertNull($date); + } +} +