Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Andreas Schamberger 2011-12-04 15:27:25 +01:00
commit d9bc76dfc3
4 changed files with 35 additions and 3 deletions

View File

@ -32,6 +32,10 @@ class DateTimeTypeConverter implements TypeConverterInterface
$doc = new \DOMDocument(); $doc = new \DOMDocument();
$doc->loadXML($data); $doc->loadXML($data);
if ('' === $doc->textContent) {
return null;
}
return new \DateTime($doc->textContent); return new \DateTime($doc->textContent);
} }
@ -40,3 +44,4 @@ class DateTimeTypeConverter implements TypeConverterInterface
return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d\TH:i:sP')); return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d\TH:i:sP'));
} }
} }

View File

@ -32,6 +32,10 @@ class DateTypeConverter implements TypeConverterInterface
$doc = new \DOMDocument(); $doc = new \DOMDocument();
$doc->loadXML($data); $doc->loadXML($data);
if ('' === $doc->textContent) {
return null;
}
return new \DateTime($doc->textContent); return new \DateTime($doc->textContent);
} }
@ -40,3 +44,4 @@ class DateTypeConverter implements TypeConverterInterface
return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d')); return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d'));
} }
} }

View File

@ -40,4 +40,15 @@ class DateTimeTypeConverterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('<dateTime>2002-10-10T12:00:00-05:00</dateTime>', $dateXml); $this->assertEquals('<dateTime>2002-10-10T12:00:00-05:00</dateTime>', $dateXml);
} }
public function testConvertNullDateTimeXmlToPhp()
{
$converter = new DateTimeTypeConverter();
$dateXml = '<sometag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>';
$date = $converter->convertXmlToPhp($dateXml);
$this->assertNull($date);
}
} }

View File

@ -38,4 +38,15 @@ class DateTypeConverterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('<date>2002-10-10</date>', $dateXml); $this->assertEquals('<date>2002-10-10</date>', $dateXml);
} }
public function testConvertNullDateTimeXmlToPhp()
{
$converter = new DateTypeConverter();
$dateXml = '<sometag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>';
$date = $converter->convertXmlToPhp($dateXml);
$this->assertNull($date);
}
} }