1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SubjectivePHPTest\Csv; |
4
|
|
|
|
5
|
|
|
use SubjectivePHP\Csv\CsvOptions; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @coversDefaultClass \SubjectivePHP\Csv\CsvOptions |
10
|
|
|
* @covers ::__construct |
11
|
|
|
*/ |
12
|
|
|
final class CsvOptionsTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
* @covers ::__construct |
17
|
|
|
* @expectedException \InvalidArgumentException |
18
|
|
|
* @expectedExceptionMessage $delimiter must be a single character string |
19
|
|
|
*/ |
20
|
|
|
public function constructWithDelimiterGreaterThanOneCharacter() |
21
|
|
|
{ |
22
|
|
|
new CsvOptions('too long'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
* @covers ::__construct |
28
|
|
|
* @expectedException \InvalidArgumentException |
29
|
|
|
* @expectedExceptionMessage $enclosure must be a single character string |
30
|
|
|
*/ |
31
|
|
|
public function constructWithEnclosureGreaterThanOneCharacter() |
32
|
|
|
{ |
33
|
|
|
new CsvOptions(',', '##'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
* @covers ::__construct |
39
|
|
|
* @expectedException \InvalidArgumentException |
40
|
|
|
* @expectedExceptionMessage $escapeChar must be a single character string |
41
|
|
|
*/ |
42
|
|
|
public function constructWithEscapeCharGreaterThanOneCharacter() |
43
|
|
|
{ |
44
|
|
|
new CsvOptions(',', '"', '\\\\'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @test |
49
|
|
|
* @covers ::getDelimiter |
50
|
|
|
*/ |
51
|
|
|
public function getDelimiter() |
52
|
|
|
{ |
53
|
|
|
$this->assertSame(',', (new CsvOptions(',', '"', '\\'))->getDelimiter()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
* @covers ::getEnclosure |
59
|
|
|
*/ |
60
|
|
|
public function getEnclosure() |
61
|
|
|
{ |
62
|
|
|
$this->assertSame('"', (new CsvOptions(',', '"', '\\'))->getEnclosure()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
* @covers ::getEscapeChar |
68
|
|
|
*/ |
69
|
|
|
public function getEscapeChar() |
70
|
|
|
{ |
71
|
|
|
$this->assertSame('\\', (new CsvOptions(',', '"', '\\'))->getEscapeChar()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|