Completed
Push — develop ( ac1c7a...ca6114 )
by Adrien
30:28 queued 32s
created

CsvTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 55
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B providerDelimiterDetection() 0 32 1
A testDelimiterDetection() 0 11 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Csv;
6
use PHPUnit\Framework\TestCase;
7
8
class CsvTest extends TestCase
9
{
10
    /**
11
     * @dataProvider providerDelimiterDetection
12
     *
13
     * @param string $filename
14
     * @param string $expectedDelimiter
15
     * @param string $cell
16
     * @param float|int|string $expectedValue
17
     */
18
    public function testDelimiterDetection($filename, $expectedDelimiter, $cell, $expectedValue)
19
    {
20
        $reader = new Csv();
21
        self::assertNull($reader->getDelimiter());
22
23
        $spreadsheet = $reader->load($filename);
24
25
        self::assertSame($expectedDelimiter, $reader->getDelimiter(), 'should be able to infer the delimiter');
26
27
        $actual = $spreadsheet->getActiveSheet()->getCell($cell)->getValue();
28
        self::assertSame($expectedValue, $actual, 'should be able to retrieve correct value');
29
    }
30
31
    public function providerDelimiterDetection()
32
    {
33
        return [
34
            [
35
                __DIR__ . '/../../data/Reader/CSV/enclosure.csv',
36
                ',',
37
                'C4',
38
                'username2',
39
            ],
40
            [
41
                __DIR__ . '/../../data/Reader/CSV/semicolon_separated.csv',
42
                ';',
43
                'C2',
44
                '25,5',
45
            ],
46
            [
47
                __DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv',
48
                ',',
49
                'B1',
50
                'Number of items with weight <= 50kg',
51
            ],
52
            [
53
                __DIR__ . '/../../../samples/Reader/sampleData/example1.csv',
54
                ',',
55
                'I4',
56
                '100%',
57
            ],
58
            [
59
                __DIR__ . '/../../../samples/Reader/sampleData/example2.csv',
60
                ',',
61
                'D8',
62
                -58.373161,
63
            ],
64
        ];
65
    }
66
}
67