File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace Ddeboer \DataImport \ValueConverter ;
44
5+ use Ddeboer \DataImport \Exception \UnexpectedValueException ;
6+
57/**
68 * Convert an date time object into string
79 */
8- class DateTimeToStringValueConverter implements ValueConverterInterface
10+ class DateTimeToStringValueConverter
911{
1012 /**
1113 * Date time format
@@ -38,8 +40,9 @@ public function convert($input)
3840 }
3941
4042 if (!($ input instanceof \DateTime)) {
41- throw new \ UnexpectedValueException ('Input must be DateTime object. ' );
43+ throw new UnexpectedValueException ('Input must be DateTime object. ' );
4244 }
4345
4446 return $ input ->format ($ this ->outputFormat );
45- }}
47+ }
48+ }
Original file line number Diff line number Diff line change @@ -11,14 +11,17 @@ public function testConvertWithoutOutputFormatReturnsString()
1111 $ value = new \DateTime ('2010-01-01 01:00:00 ' );
1212 $ converter = new DateTimeToStringValueConverter ;
1313 $ output = $ converter ->convert ($ value );
14- $ this ->assertEquals ('2010-01-01 01:00:00 ' , $ value -> format ( ' Y-m-d H:i:s ' ) );
14+ $ this ->assertEquals ('2010-01-01 01:00:00 ' , $ output );
1515 }
1616
17+ /**
18+ * @expectedException \Ddeboer\DataImport\Exception\UnexpectedValueException
19+ * @expectedExceptionMessage Input must be DateTime object
20+ */
1721 public function testInvalidInputFormatThrowsException ()
1822 {
1923 $ value = '14/10/2008 09:40:20 ' ;
2024 $ converter = new DateTimeToStringValueConverter ;
21- $ this ->setExpectedException ("UnexpectedValueException " , "Input must be DateTime object. " );
2225 $ converter ->convert ($ value );
2326 }
2427}
You can’t perform that action at this time.
0 commit comments