Skip to content

Commit b995109

Browse files
this fixes #4 one line CSV conversions will now work.
1 parent 13f06eb commit b995109

File tree

3 files changed

+6
-33
lines changed

3 files changed

+6
-33
lines changed

src/SoapBox/Formatter/Formatter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ protected function _from_csv($string, $attributes = array()) {
370370

371371
foreach ($rows as $row) {
372372
$data_fields = str_replace($escape.$enclosure, $enclosure, str_getcsv($row, $delimiter, $enclosure, $escape));
373-
374373
if (count($data_fields) > count($headings)) {
375374
array_push(self::$errors, Lang::get('formatter::formatter.more_data', array('line_number' => $line_number ) ));
376375
} else if (count($data_fields) < count($headings)) {
@@ -380,6 +379,10 @@ protected function _from_csv($string, $attributes = array()) {
380379
}
381380
}
382381

382+
if(empty($rows) && !empty($headings) && count($headings) > 0) {
383+
$data = $headings;
384+
}
385+
383386
return $data;
384387
}
385388

src/config/config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
return array(
43
'csv' => array(
54
'delimiter' => ',',

tests/FormatterTest.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ class FormatterTest extends Orchestra\Testbench\TestCase {
88
public function setUp() {
99
parent::setUp();
1010

11-
//$app = m::mock('AppMock');
12-
//$app->shouldReceive('instance')->once()->andReturn($app);
13-
14-
//Illuminate\Support\Facades\Facade::setFacadeApplication($app);
15-
//Illuminate\Support\Facades\Config::swap($config = m::mock('ConfigMock'));
16-
//Illuminate\Support\Facades\Lang::swap($lang = m::mock('ConfigLang'));
17-
18-
//$config->shouldReceive('get')->once()->with('logviewer::log_dirs')->andReturn(array('app' => 'app/storage/logs'));
19-
//$this->logviewer = new Logviewer('app', 'cgi-fcgi', '2013-06-01');
2011
}
2112
/**
2213
* A basic functional test for JSON to Array conversion
@@ -37,7 +28,6 @@ public function testJsonToArray() {
3728
*/
3829
public function testArrayToJson() {
3930
$data = array('foo'=>'bar', 'bar'=>'foo');
40-
4131
$result = Formatter::make($data)->to_json();
4232
$expected = '{"foo":"bar","bar":"foo"}';
4333
$this->assertEquals($expected, $result);
@@ -50,14 +40,11 @@ public function testArrayToJson() {
5040
*/
5141
public function testJSONToXMLToArrayToJsonToArray() {
5242
$data = '{"foo":"bar","bar":"foo"}';
53-
5443
$result = Formatter::make($data, 'json')->to_xml();
5544
$result = Formatter::make($result, 'xml')->to_array();
5645
$result = Formatter::make($result, 'array')->to_json();
5746
$result = Formatter::make($result, 'json')->to_array();
58-
5947
$expected = array('foo'=>'bar', 'bar'=>'foo');
60-
6148
$this->assertEquals($expected, $result);
6249
}
6350

@@ -67,26 +54,10 @@ public function testJSONToXMLToArrayToJsonToArray() {
6754
* @return void
6855
*/
6956
public function testCSVToArray() {
70-
$data = "foo,bar,bing,bam,boom";
57+
$data = 'foo,bar,bing,bam,boom';
7158
$result = Formatter::make($data, 'csv')->to_array();
72-
$expected = array('foo'=>'bar', 'bar'=>'foo');
73-
var_dump($result);
74-
var_dump($expected);
75-
die('dead');
59+
$expected = array('foo','bar','bing','bam','boom');
7660
$this->assertEquals($expected, $result);
7761
}
7862

79-
/**
80-
* A basic functional test for CSV data to array
81-
*
82-
* @return void
83-
*/
84-
public function testArrayToCSV() {
85-
$expected = array('foo'=>'bar', 'bar'=>'foo');
86-
$result = Formatter::make($data, 'array')->to_csv();
87-
var_dump($result);
88-
89-
$expected = "foo,bar,bing,bam,boom";
90-
$this->assertEquals($expected, $result);
91-
}
9263
}

0 commit comments

Comments
 (0)