1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SubjectivePHPTest\Csv; |
4
|
|
|
|
5
|
|
|
use SplFileObject; |
6
|
|
|
use SubjectivePHP\Csv\NoHeaderStrategy; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @coversDefaultClass \SubjectivePHP\Csv\NoHeaderStrategy |
11
|
|
|
*/ |
12
|
|
|
final class NoHeaderStrategyTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
* @covers ::getHeaders |
17
|
|
|
*/ |
18
|
|
|
public function getHeaders() |
19
|
|
|
{ |
20
|
|
|
$fileObject = new SplFileObject(__DIR__ . '/_files/no_headers.csv'); |
21
|
|
|
$fileObject->setFlags(SplFileObject::READ_CSV); |
22
|
|
|
$fileObject->setCsvControl(','); |
23
|
|
|
$strategy = new NoHeaderStrategy(); |
24
|
|
|
$this->assertSame( |
25
|
|
|
[0, 1, 2, 3, 4, 5, 6], |
26
|
|
|
$strategy->getHeaders($fileObject) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
* @covers ::isHeaderRow |
33
|
|
|
*/ |
34
|
|
|
public function isHeaderRowAlwaysReturnsFalse() |
35
|
|
|
{ |
36
|
|
|
$fileObject = new SplFileObject(__DIR__ . '/_files/no_headers.csv'); |
37
|
|
|
$fileObject->setFlags(SplFileObject::READ_CSV); |
38
|
|
|
$fileObject->setCsvControl(','); |
39
|
|
|
$strategy = new NoHeaderStrategy(); |
40
|
|
|
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv())); |
41
|
|
|
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv())); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
* @covers ::createDataRow |
47
|
|
|
*/ |
48
|
|
|
public function createDataRow() |
49
|
|
|
{ |
50
|
|
|
$row = [ |
51
|
|
|
'bk101', |
52
|
|
|
'Gambardella, Matthew', |
53
|
|
|
'XML Developer\'s Guide', |
54
|
|
|
'Computer', |
55
|
|
|
'44.95', |
56
|
|
|
'2000-10-01', |
57
|
|
|
'An in-depth look at creating applications with XML.', |
58
|
|
|
]; |
59
|
|
|
$strategy = new NoHeaderStrategy(); |
60
|
|
|
$this->assertSame( |
61
|
|
|
[ |
62
|
|
|
'bk101', |
63
|
|
|
'Gambardella, Matthew', |
64
|
|
|
'XML Developer\'s Guide', |
65
|
|
|
'Computer', |
66
|
|
|
'44.95', |
67
|
|
|
'2000-10-01', |
68
|
|
|
'An in-depth look at creating applications with XML.', |
69
|
|
|
], |
70
|
|
|
$strategy->createDataRow($row) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|