Completed
Push — master ( 461219...630231 )
by Harry
04:03
created

ReFormatTest::testReFormatFromCsvToJson()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/data-file
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/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Integration\Modify;
15
16
use Graze\DataFile\Format\CsvFormat;
17
use Graze\DataFile\Format\JsonFormat;
18
use Graze\DataFile\Modify\ReFormat;
19
use Graze\DataFile\Node\LocalFile;
20
use Graze\DataFile\Test\AbstractFileTestCase;
21
22
class ReFormatTest extends AbstractFileTestCase
23
{
24
    public function testReFormatFromCsvToJson()
25
    {
26
        $file = new LocalFile(static::$dir . 'reFormatInput.csv');
27
        $file->setFormat(new CsvFormat([
28
            'headerRow' => 1,
29
        ]));
30
31
        $input = <<<CSV
32
"first","second","third"
33
"1","cake","monkies"
34
"2","banana","fish"
35
CSV;
36
        $file->write($input);
37
38
        $output = new LocalFile(static::$dir . 'reFormatOutput.json');
39
        $output->setFormat(new JsonFormat([
40
            'fileType' => JsonFormat::JSON_FILE_TYPE_EACH_LINE,
41
        ]));
42
43
        $reFormat = new ReFormat();
44
45
        $reFormat->reFormat($file, null, $output);
46
47
        $expected = <<<JSON
48
{"first":"1","second":"cake","third":"monkies"}
49
{"first":"2","second":"banana","third":"fish"}
50
JSON;
51
52
        static::assertEquals($expected, $output->read());
53
    }
54
}
55