Skip to content

Commit 043baa8

Browse files
committed
Move files to PSR-4 location and improve test
1 parent 37fd273 commit 043baa8

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/Ddeboer/DataImport/ValueConverter/DateTimeToStringValueConverter.php renamed to src/ValueConverter/DateTimeToStringValueConverter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace 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+
}

tests/Ddeboer/DataImport/Tests/ValueConverter/DateTimeToStringValueConverterTest.php renamed to tests/ValueConverter/DateTimeToStringValueConverterTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)