Passed
Pull Request — master (#7)
by Jean Paul
01:59
created

testSetterGetterAttributeEnclosure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Core\Extractors;
4
5
use PHPUnit\Framework\TestCase;
6
use Coco\SourceWatcher\Core\Extractors\CsvExtractor;
7
use Coco\SourceWatcher\Core\Row;
8
9
class CsvExtractorTest extends TestCase
10
{
11
    public function testSetterGetterAttributeColumns () : void
12
    {
13
        $csvExtractor = new CsvExtractor();
14
15
        $givenColumns = array( "id", "name", "email" );
16
        $expectedColumns = array( "id", "name", "email" );
17
18
        $csvExtractor->setColumns( $givenColumns );
19
20
        $this->assertEquals( $expectedColumns, $csvExtractor->getColumns() );
21
    }
22
23
    public function testSetterGetterAttributeDelimiter () : void
24
    {
25
        $csvExtractor = new CsvExtractor();
26
27
        $givenDelimiter = ",";
28
        $expectedDelimiter = ",";
29
30
        $csvExtractor->setDelimiter( $givenDelimiter );
31
32
        $this->assertEquals( $expectedDelimiter, $csvExtractor->getDelimiter() );
33
    }
34
35
    public function testSetterGetterAttributeEnclosure () : void
36
    {
37
        $csvExtractor = new CsvExtractor();
38
39
        $givenEnclosure = "\"";
40
        $expectedEnclosure = "\"";
41
42
        $csvExtractor->setEnclosure( $givenEnclosure );
43
44
        $this->assertEquals( $expectedEnclosure, $csvExtractor->getEnclosure() );
45
    }
46
47
    public function testSetterGetterAttributeInput () : void
48
    {
49
        $csvExtractor = new CsvExtractor();
50
51
        $givenInput = "/some/file/path/file.csv";
52
        $expectedInput = "/some/file/path/file.csv";
53
54
        $csvExtractor->setInput( $givenInput );
55
56
        $this->assertEquals( $expectedInput, $csvExtractor->getInput() );
57
    }
58
59
    public function testLoadCsvWithDefaultOptions () : void
60
    {
61
        $csvExtractor = new CsvExtractor();
62
63
        $expected = [ new Row( [ "id" => 1, "name" => "John Doe", "email" => "[email protected]" ] ), new Row( [ "id" => 2, "name" => "Jane Doe", "email" => "[email protected]" ] ) ];
64
65
        $csvExtractor->setInput( __DIR__ . "/../../../samples/data/csv/csv1.csv" );
66
67
        $this->assertEquals( $expected, $csvExtractor->extract() );
68
    }
69
}
70