Passed
Push — master ( 0e441f...fe9525 )
by Daniel
02:35
created

HeaderTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSkipDuplicateColumns() 0 11 1
A testGetColumns() 0 4 1
A testAddColumn() 0 6 1
A testArrayOfNonStrings() 0 10 1
A testCreateFromArray() 0 9 1
A getTestHeaderArray() 0 3 1
A testCreateHeader() 0 4 1
1
<?php declare(strict_types=1);
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\Header;
13
14
15
use PHPUnit\Framework\TestCase;
16
use RoadBunch\Csv\Exceptions\InvalidHeaderArrayException;
17
use RoadBunch\Csv\Header\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
        $testHeaderArray = $this->getTestHeaderArray();
63
64
        $header = new Header($testHeaderArray);
65
        $this->assertCount(count($testHeaderArray), $header->getColumns());
66
67
        $header->addColumn('employee id');
68
        $this->assertCount(count($testHeaderArray) + 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 getTestHeaderArray(): array
90
    {
91
        return ['first_name', 'last_name', 'birthday', 'phone_number', 'email_address'];
92
    }
93
}
94