Permalink
Browse files

Adding option to specify extension along with file path. Adding unit …

…test for this permatation
  • Loading branch information...
1 parent 325e865 commit 812600ad6f1f846d0e657d322468097494c37048 @IamSmith committed Mar 28, 2012
Showing with 21 additions and 3 deletions.
  1. +11 −3 PhpReader.php
  2. +3 −0 Test/Files/testFileNoExtension
  3. +7 −0 Test/PhpReaderTest.php
View
@@ -14,16 +14,24 @@ class PhpReader {
const OPTION_IGNORE_HEADER_ROW = 1;
- static function getReader($pathToFile) {
+ static function getReader($pathToFile, $extensionOverride = null) {
$options = func_get_args();
+ if (is_numeric($extensionOverride)) {
+ $extensionOverride = null;
+ }
+
if (!file_exists($pathToFile)) {
throw new FileDoesntExistException("'$pathToFile' doesn't exist");
}
- $extension = PhpReader::determineFileType($pathToFile);
- $className = ucfirst($extension);
+ if ($extensionOverride == null) {
+ $extension = PhpReader::determineFileType($pathToFile);
+ } else {
+ $extension = strtolower($extensionOverride);
+ }
+ $className = ucfirst($extension);
return ExtensionFactory::$className($pathToFile, $options);
}
@@ -0,0 +1,3 @@
+"Title","FirstName","LastName","EmailAddress","Date","DateOfBirth"
+"","Karoly","Sefel","xxxx@gmail.com","2012-03-30 22:52:34.185199","1985-02-13 00:00:00"
+"","Julian","Webb","xxxx@msn.com","2012-03-30 22:52:34.253219","1970-01-01 00:00:00"
@@ -124,4 +124,11 @@ public function testLargeXlsxFile() {
$this->assertLessThan(10, $timeTaken);
}
+ public function testExtensionOverrideFile() {
+ $reader = PhpReader::getReader("Test/Files/testFileNoExtension", "csv");
+ foreach ($reader as $rowNumber => $rowData) {
+
+ }
+ }
+
}

0 comments on commit 812600a

Please sign in to comment.