Test Failed
Push — master ( c6f077...3d80e3 )
by Daniel
01:58
created

HeaderTest::testSkipDuplicateColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv\Tests;
13
14
15
use PHPUnit\Framework\TestCase;
16
use RoadBunch\Csv\Exceptions\InvalidHeaderArrayException;
17
use RoadBunch\Csv\Header;
18
19
/**
20
 * Class HeaderTest
21
 *
22
 * @author  Dan McAdams
23
 * @package RoadBunch\Csv\Tests
24
 */
25
class HeaderTest extends TestCase
26
{
27
    public function testCreateHeader()
28
    {
29
        $header = new Header();
30
        $this->assertNotNull($header);
31
    }
32
33
    public function testGetColumns()
34
    {
35
        $header = new Header();
36
        $this->assertInternalType('array', $header->getColumns());
37
    }
38
39
    public function testAddColumn()
40
    {
41
        $header = new Header();
42
        $header->addColumn('First Name');
43
44
        $this->assertCount(1, $header->getColumns());
45
    }
46
47
    public function testSkipDuplicateColumns()
48
    {
49
        $header = new Header();
50
51
        // test adding duplicate columns
52
        $header->addColumn('Test Column Three This should only be added once');
53
        $header->addColumn('Test Column Three This should only be added once');
54
        $header->addColumn('Test Column Four');
55
        $header->addColumn('Test Column Five');
56
57
        $this->assertCount(3, $header->getColumns());
58
    }
59
60
    public function testCreateFromArray()
61
    {
62
        $testHeader = $this->getTestHeader();
63
64
        $header = new Header($testHeader);
65
        $this->assertCount(count($testHeader), $header->getColumns());
66
67
        $header->addColumn('employee id');
68
        $this->assertCount(count($testHeader)+1, $header->getColumns());
69
    }
70
71
    /**
72
     * @throws InvalidHeaderArrayException
73
     */
74
    public function testArrayOfNonStrings()
75
    {
76
        $this->expectException(InvalidHeaderArrayException::class);
77
78
        $multiArray = [
79
            ['an array'],
80
            new \stdClass(),
81
            $this
82
        ];
83
        new Header($multiArray);
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    private function getTestHeader(): array
90
    {
91
        return ['firstname', 'lastname', 'birthday', 'phone number', 'email address'];
92
    }
93
}
94