Passed
Push — master ( 6998a3...224daf )
by Daniel
02:08
created

CsvOptionsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv\Tests\Csv;
13
14
15
use PHPUnit\Framework\TestCase;
16
use Psr\Log\NullLogger;
17
use RoadBunch\Csv as Csv;
18
19
/**
20
 * Class CsvTest
21
 *
22
 * @author  Dan McAdams
23
 * @package RoadBunch\Csv\Tests\Csv
24
 */
25
class CsvOptionsTest extends TestCase
26
{
27
    public function testCsvAcceptsLogger()
28
    {
29
        $csv = new CsvSpy(new NullLogger());
30
        $this->assertNotNull($csv);
31
    }
32
33
    public function testDefaultOptions()
34
    {
35
        $csv = new CsvSpy();
36
        $this->assertEquals(Csv\Delimiter::DELIMITER_COMMA          , $csv->getDelimiter());
37
        $this->assertEquals(Csv\Enclosure::ENCLOSURE_DOUBLE_QUOTE   , $csv->getEnclosure());
38
        $this->assertEquals(Csv\Newline::NEWLINE_LF                 , $csv->getNewline());
39
        $this->assertEquals(Csv\Escape::ESCAPE_CHAR                 , $csv->getEscapeCharacter());
40
    }
41
42
    public function testSetDelimiter()
43
    {
44
        $csv           = new CsvSpy();
45
        $testDelimiter = Csv\Delimiter::DELIMITER_COLON;
46
47
        $csv->setDelimiter($testDelimiter);
48
        $this->assertEquals($testDelimiter, $csv->getDelimiter());
49
    }
50
51
    public function testSetEnclosure()
52
    {
53
        $csv           = new CsvSpy();
54
        $testEnclosure = Csv\Enclosure::ENCLOSURE_SINGLE_QUOTE;
55
56
        $csv->setEnclosure($testEnclosure);
57
        $this->assertEquals($testEnclosure, $csv->getEnclosure());
58
    }
59
60
    public function testSetNewline()
61
    {
62
        $csv         = new CsvSpy();
63
        $testNewline = Csv\Newline::NEWLINE_CRLF;
64
65
        $csv->setNewline($testNewline);
66
        $this->assertEquals($testNewline, $csv->getNewline());
67
    }
68
69
    public function testSetEscape()
70
    {
71
        $csv        = new CsvSpy();
72
        $testEscape = "esc";
73
74
        $csv->setEscape($testEscape);
75
        $this->assertEquals($testEscape, $csv->getEscapeCharacter());
76
    }
77
}
78