1
|
|
|
<?php |
2
|
|
|
namespace DominionEnterprises\ColumnParser; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @coversDefaultClass \DominionEnterprises\ColumnParser\MultispacedHeadersParser |
8
|
|
|
*/ |
9
|
|
|
class MultispacedHeadersParserTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
private $emptyData; |
12
|
|
|
private $onlyHeaderData; |
13
|
|
|
private $sampleData; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->emptyData = ''; |
18
|
|
|
$this->onlyHeaderData = 'Name Age City of Birth'; |
19
|
|
|
$this->sampleData = <<<EOS |
20
|
|
|
Name Age City of Birth |
21
|
|
|
James 17 San Francisco, CA |
22
|
|
|
Mary 18 Washington, D.C. |
23
|
|
|
William 22 Dallas, TX |
24
|
|
|
EOS; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @test |
29
|
|
|
* @covers ::__construct |
30
|
|
|
* @covers ::getRows |
31
|
|
|
*/ |
32
|
|
|
public function getRowsFromSampleData() |
33
|
|
|
{ |
34
|
|
|
$parser = new MultispacedHeadersParser($this->sampleData); |
35
|
|
|
$this->assertSame( |
36
|
|
|
[ |
37
|
|
|
['Name' => 'James', 'Age' => '17', 'City of Birth' => 'San Francisco, CA'], |
38
|
|
|
['Name' => 'Mary', 'Age' => '18', 'City of Birth' => 'Washington, D.C.'], |
39
|
|
|
['Name' => 'William', 'Age' => '22', 'City of Birth' => 'Dallas, TX'], |
40
|
|
|
], |
41
|
|
|
$parser->getRows() |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
* @covers ::__construct |
48
|
|
|
* @covers ::getRows |
49
|
|
|
*/ |
50
|
|
|
public function getRowsFromEmptyData() |
51
|
|
|
{ |
52
|
|
|
$parser = new MultispacedHeadersParser($this->emptyData); |
53
|
|
|
$this->assertSame([], $parser->getRows()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
* @covers ::__construct |
59
|
|
|
* @covers ::getRows |
60
|
|
|
*/ |
61
|
|
|
public function getRowsFromOnlyHeaderData() |
62
|
|
|
{ |
63
|
|
|
$parser = new MultispacedHeadersParser($this->onlyHeaderData); |
64
|
|
|
$this->assertSame([], $parser->getRows()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
* @covers ::__construct |
70
|
|
|
* @covers ::getHeaders |
71
|
|
|
*/ |
72
|
|
|
public function getHeadersFromSampleData() |
73
|
|
|
{ |
74
|
|
|
$parser = new MultispacedHeadersParser($this->sampleData); |
75
|
|
|
$this->assertSame(['Name', 'Age', 'City of Birth'], $parser->getHeaders()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
* @covers ::__construct |
81
|
|
|
* @covers ::getHeaders |
82
|
|
|
*/ |
83
|
|
|
public function getHeadersFromEmptyData() |
84
|
|
|
{ |
85
|
|
|
$parser = new MultispacedHeadersParser($this->emptyData); |
86
|
|
|
$this->assertSame([], $parser->getHeaders()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @test |
91
|
|
|
* @covers ::__construct |
92
|
|
|
* @covers ::getHeaders |
93
|
|
|
*/ |
94
|
|
|
public function getHeadersFromOnlyHeaderData() |
95
|
|
|
{ |
96
|
|
|
$parser = new MultispacedHeadersParser($this->onlyHeaderData); |
97
|
|
|
$this->assertSame(['Name', 'Age', 'City of Birth'], $parser->getHeaders()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|