Completed
Pull Request — master (#31)
by Chad
01:44
created

NoHeaderStrategyTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 63
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 11 1
A isHeaderRowAlwaysReturnsFalse() 0 9 1
B createDataRow() 0 25 1
1
<?php
2
3
namespace SubjectivePHPTest\Csv;
4
5
use SplFileObject;
6
use SubjectivePHP\Csv\NoHeaderStrategy;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @coversDefaultClass \SubjectivePHP\Csv\NoHeaderStrategy
11
 */
12
final class NoHeaderStrategyTest extends TestCase
13
{
14
    /**
15
     * @test
16
     * @covers ::getHeaders
17
     */
18
    public function getHeaders()
19
    {
20
        $fileObject = new SplFileObject(__DIR__ . '/_files/no_headers.csv');
21
        $fileObject->setFlags(SplFileObject::READ_CSV);
22
        $fileObject->setCsvControl(',');
23
        $strategy = new NoHeaderStrategy();
24
        $this->assertSame(
25
            [0, 1, 2, 3, 4, 5, 6],
26
            $strategy->getHeaders($fileObject)
27
        );
28
    }
29
30
    /**
31
     * @test
32
     * @covers ::isHeaderRow
33
     */
34
    public function isHeaderRowAlwaysReturnsFalse()
35
    {
36
        $fileObject = new SplFileObject(__DIR__ . '/_files/no_headers.csv');
37
        $fileObject->setFlags(SplFileObject::READ_CSV);
38
        $fileObject->setCsvControl(',');
39
        $strategy = new NoHeaderStrategy();
40
        $this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
41
        $this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
42
    }
43
44
    /**
45
     * @test
46
     * @covers ::createDataRow
47
     */
48
    public function createDataRow()
49
    {
50
        $row = [
51
            'bk101',
52
            'Gambardella, Matthew',
53
            'XML Developer\'s Guide',
54
            'Computer',
55
            '44.95',
56
            '2000-10-01',
57
            'An in-depth look at creating applications with XML.',
58
        ];
59
        $strategy = new NoHeaderStrategy();
60
        $this->assertSame(
61
            [
62
                'bk101',
63
                'Gambardella, Matthew',
64
                'XML Developer\'s Guide',
65
                'Computer',
66
                '44.95',
67
                '2000-10-01',
68
                'An in-depth look at creating applications with XML.',
69
            ],
70
            $strategy->createDataRow($row)
71
        );
72
    }
73
74
}
75