Completed
Push — master ( e8fccd...9c2126 )
by Harry
02:44
created

CsvConfigurationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testImplementsInterface() 0 6 1
A testDefaultsAreAssignedWhenNoOptionsSupplied() 0 11 1
A testAssigningOptionsModifiesTheDefinition() 0 18 1
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\CsvToken\Test\Unit\Format;
15
16
use Graze\CsvToken\Csv\CsvConfiguration;
17
use Graze\CsvToken\Csv\CsvConfigurationInterface;
18
use Graze\CsvToken\Test\TestCase;
19
20
class CsvConfigurationTest extends TestCase
21
{
22
    public function testImplementsInterface()
23
    {
24
        $definition = new CsvConfiguration();
25
26
        static::assertInstanceOf(CsvConfigurationInterface::class, $definition);
27
    }
28
29
    public function testDefaultsAreAssignedWhenNoOptionsSupplied()
30
    {
31
        $definition = new CsvConfiguration();
32
33
        static::assertEquals(',', $definition->getDelimiter(), "Default Delimiter should be ','");
34
        static::assertEquals('"', $definition->getQuote(), "Default quote character should be \"");
35
        static::assertEquals('\\N', $definition->getNullValue(), "Null character should be '\\N'");
36
        static::assertEquals("\n", $definition->getNewLine(), "Line terminator should be '\\n'");
37
        static::assertEquals('\\', $definition->getEscape(), "Default escape character should be '\\'");
38
        static::assertEquals(false, $definition->useDoubleQuotes(), "Double quote should be off by default");
39
    }
40
41
    public function testAssigningOptionsModifiesTheDefinition()
42
    {
43
        $definition = new CsvConfiguration([
44
            'delimiter'   => "\t",
45
            'quote'       => '',
46
            'null'        => '',
47
            'newLine'     => "----",
48
            'escape'      => '"',
49
            'doubleQuote' => true,
50
        ]);
51
52
        static::assertEquals("\t", $definition->getDelimiter(), "Delimiter should be set to '\\t' (tab)");
53
        static::assertEquals('', $definition->getQuote(), "Quote character should be blank");
54
        static::assertEquals('', $definition->getNullValue(), "Null character should be '' (blank)'");
55
        static::assertEquals("----", $definition->getNewLine(), "Line terminator should be '----'");
56
        static::assertEquals('"', $definition->getEscape(), 'Escape Character should be "');
57
        static::assertEquals(true, $definition->useDoubleQuotes(), 'double quote should be on');
58
    }
59
}
60