Skip to content

Commit 6783edb

Browse files
committed
fix indentation
1 parent 009375c commit 6783edb

File tree

2 files changed

+87
-87
lines changed

2 files changed

+87
-87
lines changed

lib/Serialization.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -340,32 +340,32 @@ private function write($data, $tag=null)
340340
*/
341341
class CsvSerializer extends Serialization
342342
{
343-
public static $delimiter = ',';
344-
public static $enclosure = '"';
345-
346-
public function to_s()
347-
{
348-
if (@$this->options['only_header'] == true) return $this->header();
349-
return $this->row();
350-
}
351-
352-
private function header()
353-
{
354-
return $this->to_csv(array_keys($this->to_a()));
355-
}
356-
357-
private function row()
358-
{
359-
return $this->to_csv($this->to_a());
360-
}
361-
362-
private function to_csv($arr)
363-
{
364-
$outstream = fopen('php://temp', 'w');
365-
fputcsv($outstream, $arr, self::$delimiter, self::$enclosure);
366-
rewind($outstream);
367-
$buffer = trim(stream_get_contents($outstream));
368-
fclose($outstream);
369-
return $buffer;
370-
}
371-
}
343+
public static $delimiter = ',';
344+
public static $enclosure = '"';
345+
346+
public function to_s()
347+
{
348+
if (@$this->options['only_header'] == true) return $this->header();
349+
return $this->row();
350+
}
351+
352+
private function header()
353+
{
354+
return $this->to_csv(array_keys($this->to_a()));
355+
}
356+
357+
private function row()
358+
{
359+
return $this->to_csv($this->to_a());
360+
}
361+
362+
private function to_csv($arr)
363+
{
364+
$outstream = fopen('php://temp', 'w');
365+
fputcsv($outstream, $arr, self::$delimiter, self::$enclosure);
366+
rewind($outstream);
367+
$buffer = trim(stream_get_contents($outstream));
368+
fclose($outstream);
369+
return $buffer;
370+
}
371+
}

test/SerializationTest.php

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,30 @@ public function test_to_xml()
123123
$this->assert_equals($book->attributes(),get_object_vars(new SimpleXMLElement($book->to_xml())));
124124
}
125125

126-
public function test_to_array()
127-
{
128-
$book = Book::find(1);
126+
public function test_to_array()
127+
{
128+
$book = Book::find(1);
129129
$array = $book->to_array();
130130
$this->assert_equals($book->attributes(), $array);
131-
}
131+
}
132132

133-
public function test_to_array_include_root()
134-
{
133+
public function test_to_array_include_root()
134+
{
135135
ActiveRecord\ArraySerializer::$include_root = true;
136-
$book = Book::find(1);
136+
$book = Book::find(1);
137137
$array = $book->to_array();
138-
$book_attributes = array('book' => $book->attributes());
138+
$book_attributes = array('book' => $book->attributes());
139139
$this->assert_equals($book_attributes, $array);
140-
}
140+
}
141141

142-
public function test_to_array_except()
143-
{
144-
$book = Book::find(1);
142+
public function test_to_array_except()
143+
{
144+
$book = Book::find(1);
145145
$array = $book->to_array(array('except' => array('special')));
146146
$book_attributes = $book->attributes();
147147
unset($book_attributes['special']);
148148
$this->assert_equals($book_attributes, $array);
149-
}
149+
}
150150

151151
public function test_works_with_datetime()
152152
{
@@ -166,49 +166,49 @@ public function test_only_method()
166166
$this->assert_contains('<sharks>lasers</sharks>', Author::first()->to_xml(array('only_method' => 'return_something')));
167167
}
168168

169-
public function test_to_csv()
170-
{
171-
$book = Book::find(1);
172-
$this->assert_equals('1,1,2,"Ancient Art of Main Tanking",0,0',$book->to_csv());
173-
}
174-
175-
public function test_to_csv_only_header()
176-
{
177-
$book = Book::find(1);
178-
$this->assert_equals('book_id,author_id,secondary_author_id,name,numeric_test,special',
179-
$book->to_csv(array('only_header'=>true))
180-
);
181-
}
182-
183-
public function test_to_csv_only_method()
184-
{
185-
$book = Book::find(1);
186-
$this->assert_equals('2,"Ancient Art of Main Tanking"',
187-
$book->to_csv(array('only'=>array('name','secondary_author_id')))
188-
);
189-
}
190-
191-
public function test_to_csv_only_method_on_header()
192-
{
193-
$book = Book::find(1);
194-
$this->assert_equals('secondary_author_id,name',
195-
$book->to_csv(array('only'=>array('secondary_author_id','name'),
196-
'only_header'=>true))
197-
);
198-
}
199-
200-
public function test_to_csv_with_custom_delimiter()
201-
{
202-
$book = Book::find(1);
203-
ActiveRecord\CsvSerializer::$delimiter=';';
204-
$this->assert_equals('1;1;2;"Ancient Art of Main Tanking";0;0',$book->to_csv());
205-
}
206-
207-
public function test_to_csv_with_custom_enclosure()
208-
{
209-
$book = Book::find(1);
210-
ActiveRecord\CsvSerializer::$delimiter=',';
211-
ActiveRecord\CsvSerializer::$enclosure="'";
212-
$this->assert_equals("1,1,2,'Ancient Art of Main Tanking',0,0",$book->to_csv());
213-
}
169+
public function test_to_csv()
170+
{
171+
$book = Book::find(1);
172+
$this->assert_equals('1,1,2,"Ancient Art of Main Tanking",0,0',$book->to_csv());
173+
}
174+
175+
public function test_to_csv_only_header()
176+
{
177+
$book = Book::find(1);
178+
$this->assert_equals('book_id,author_id,secondary_author_id,name,numeric_test,special',
179+
$book->to_csv(array('only_header'=>true))
180+
);
181+
}
182+
183+
public function test_to_csv_only_method()
184+
{
185+
$book = Book::find(1);
186+
$this->assert_equals('2,"Ancient Art of Main Tanking"',
187+
$book->to_csv(array('only'=>array('name','secondary_author_id')))
188+
);
189+
}
190+
191+
public function test_to_csv_only_method_on_header()
192+
{
193+
$book = Book::find(1);
194+
$this->assert_equals('secondary_author_id,name',
195+
$book->to_csv(array('only'=>array('secondary_author_id','name'),
196+
'only_header'=>true))
197+
);
198+
}
199+
200+
public function test_to_csv_with_custom_delimiter()
201+
{
202+
$book = Book::find(1);
203+
ActiveRecord\CsvSerializer::$delimiter=';';
204+
$this->assert_equals('1;1;2;"Ancient Art of Main Tanking";0;0',$book->to_csv());
205+
}
206+
207+
public function test_to_csv_with_custom_enclosure()
208+
{
209+
$book = Book::find(1);
210+
ActiveRecord\CsvSerializer::$delimiter=',';
211+
ActiveRecord\CsvSerializer::$enclosure="'";
212+
$this->assert_equals("1,1,2,'Ancient Art of Main Tanking',0,0",$book->to_csv());
213+
}
214214
}

0 commit comments

Comments
 (0)