1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/csv-token |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/csv-token/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/csv-token |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\CsvToken\Test\Unit; |
15
|
|
|
|
16
|
|
|
use Graze\CsvToken\Csv\CsvConfiguration; |
17
|
|
|
use Graze\CsvToken\Csv\CsvConfigurationInterface; |
18
|
|
|
use Graze\CsvToken\Reader; |
19
|
|
|
use Graze\CsvToken\Test\TestCase; |
20
|
|
|
use Mockery as m; |
21
|
|
|
|
22
|
|
|
class ReaderTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @dataProvider parseData |
26
|
|
|
* |
27
|
|
|
* @param CsvConfigurationInterface $config |
28
|
|
|
* @param string $csv |
29
|
|
|
* @param array $expected |
30
|
|
|
*/ |
31
|
|
|
public function testParse(CsvConfigurationInterface $config, $csv, array $expected) |
32
|
|
|
{ |
33
|
|
|
$reader = new Reader($config, $this->getStream($csv)); |
34
|
|
|
|
35
|
|
|
$results = iterator_to_array($reader->read()); |
36
|
|
|
|
37
|
|
|
static::assertEquals($expected, $results); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function parseData() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
[ |
47
|
|
|
new CsvConfiguration(), |
48
|
|
|
'"some",\\N,"new' . "\n" . 'line",with\\' . "\n" . 'escaped,"in\\' . "\n" . 'quotes","\\\\"', |
49
|
|
|
[ |
50
|
|
|
['some', null, "new\nline", "with\nescaped", "in\nquotes", '\\'], |
51
|
|
|
], |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|