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

HeaderStrategyTest::derive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace SubjectivePHPTest\Csv;
4
5
use SplFileObject;
6
use SubjectivePHP\Csv\HeaderStrategy;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @coversDefaultClass \SubjectivePHP\Csv\HeaderStrategy
11
 * @covers ::getHeaders
12
 * @covers ::<private>
13
 */
14
final class HeaderStrategyTest extends TestCase
15
{
16
    /**
17
     * @test
18
     * @covers ::derive
19
     */
20 View Code Duplication
    public function derive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $fileObject = $this->getFileObject('pipe_delimited.txt', '|');
23
        $strategy = HeaderStrategy::derive();
24
        $this->assertSame(
25
            ['id', 'author', 'title', 'genre', 'price', 'publish_date', 'description'],
26
            $strategy->getHeaders($fileObject)
27
        );
28
    }
29
30
    /**
31
     * @test
32
     * @covers ::provide
33
     */
34
    public function provide()
35
    {
36
        $headers = ['id', 'author', 'title', 'genre', 'price', 'publish_date', 'description'];
37
        $fileObject = $this->getFileObject('basic.csv');
38
        $strategy = HeaderStrategy::provide($headers);
39
        $this->assertSame($headers, $strategy->getHeaders($fileObject));
40
    }
41
42
    /**
43
     * @test
44
     * @covers ::none
45
     */
46 View Code Duplication
    public function none()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $fileObject = $this->getFileObject('no_headers.csv');
49
        $strategy = HeaderStrategy::none();
50
        $this->assertSame(
51
            [0, 1, 2, 3, 4, 5, 6],
52
            $strategy->getHeaders($fileObject)
53
        );
54
    }
55
56
    public function getFileObject(string $fileName, string $delimiter = ',') : SplFileObject
57
    {
58
         $fileObject = new SplFileObject(__DIR__ . "/_files/{$fileName}");
59
         $fileObject->setFlags(SplFileObject::READ_CSV);
60
         $fileObject->setCsvControl($delimiter);
61
         return $fileObject;
62
    }
63
}
64