Completed
Pull Request — master (#42)
by Sam
02:33
created

CsvTableWriterTest::testCsvReading()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 2
eloc 12
nc 2
nop 0
1
<?php
2
3
use SilverStripe\SsPak\DataExtractor\CsvTableWriter;
4
5
class CsvTableWriterTest extends PHPUnit_Framework_TestCase
6
{
7
	function testCsvReading() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8
9
		if (file_exists('/tmp/output.csv')) {
10
			unlink('/tmp/output.csv');
11
		}
12
13
		$csv = new CsvTableWriter('/tmp/output.csv');
14
15
		$csv->start(['Col1', 'Col2', 'Col3']);
16
		$csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]);
17
		$csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]);
18
		$csv->finish();
19
20
		$csvContent = file_get_contents('/tmp/output.csv');
21
		unlink('/tmp/output.csv');
22
23
		$fixture = file_get_contents(__DIR__ . '/fixture/input.csv');
24
25
		$this->assertEquals($fixture, $csvContent);
26
	}
27
28
	function testNoStartCall() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
30
		if (file_exists('/tmp/output.csv')) {
31
			unlink('/tmp/output.csv');
32
		}
33
34
		$csv = new CsvTableWriter('/tmp/output.csv');
35
36
		$csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]);
37
		$csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]);
38
		$csv->finish();
39
40
		$csvContent = file_get_contents('/tmp/output.csv');
41
		unlink('/tmp/output.csv');
42
43
		$fixture = file_get_contents(__DIR__ . '/fixture/input.csv');
44
45
		$this->assertEquals($fixture, $csvContent);
46
	}
47
48
}
49