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

CsvTableWriterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCsvReading() 0 20 2
A testNoStartCall() 0 19 2
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