Fixed failing test

This commit is contained in:
Bernhard Schussek 2012-12-15 18:04:13 +01:00 committed by Fabien Potencier
parent 47a56048f3
commit e713bb4e7e
2 changed files with 15 additions and 13 deletions

View File

@ -140,6 +140,17 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
$outputTz = new \DateTimeZone($this->outputTimezone);
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
$lastErrors = \DateTime::getLastErrors();
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
throw new TransformationFailedException(
implode(', ', array_merge(
array_values($lastErrors['warnings']),
array_values($lastErrors['errors'])
))
);
}
// On PHP versions < 5.3.8 we need to emulate the pipe operator
// and reset parts not given in the format to their equivalent
// of the UNIX base timestamp.
@ -204,17 +215,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
}
}
$lastErrors = \DateTime::getLastErrors();
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
throw new TransformationFailedException(
implode(', ', array_merge(
array_values($lastErrors['warnings']),
array_values($lastErrors['errors'])
))
);
}
if ($this->inputTimezone !== $this->outputTimezone) {
$dateTime->setTimeZone(new \DateTimeZone($this->inputTimezone));
}

View File

@ -876,8 +876,10 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
public function testDateTimeWithEmptyValueOnTime()
{
$form = $this->factory->createNamed('name', 'datetime', '2011-02-03', array(
'input' => 'string',
$data = array('year' => '2011', 'month' => '2', 'day' => '3', 'hour' => '', 'minute' => '');
$form = $this->factory->createNamed('name', 'datetime', $data, array(
'input' => 'array',
'empty_value' => array('hour' => 'Change&Me', 'minute' => 'Change&Me'),
'required' => false,
));