Failed Conditions
Pull Request — master (#31)
by Chad
01:33
created

ProvidedHeaderStrategyTest::getHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace SubjectivePHPTest\Csv;
4
5
use SplFileObject;
6
use SubjectivePHP\Csv\ProvidedHeaderStrategy;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @coversDefaultClass \SubjectivePHP\Csv\ProvidedHeaderStrategy
11
 * @covers ::__construct
12
 */
13
final class ProvidedHeaderStrategyTest extends TestCase
14
{
15
    const HEADERS = ['id', 'author', 'title', 'genre', 'price', 'publish_date', 'description'];
16
17
    /**
18
     * @test
19
     * @covers ::getHeaders
20
     */
21
    public function getHeaders()
22
    {
23
        $fileObject = $this->getFileObject();
24
        $strategy = $this->getStrategy();
25
        $this->assertSame(self::HEADERS, $strategy->getHeaders($fileObject));
26
    }
27
28
    /**
29
     * @test
30
     * @covers ::isHeaderRow
31
     */
32
    public function rowIsHeaderRow()
33
    {
34
        $strategy = $this->getStrategy();
35
        $this->assertTrue($strategy->isHeaderRow(self::HEADERS));
36
    }
37
38
    /**
39
     * @test
40
     * @covers ::isHeaderRow
41
     */
42
    public function rowIsNotHeaderRow()
43
    {
44
        $strategy = $this->getStrategy();
45
        $fileObject = $this->getFileObject();
46
        $fileObject->fgetcsv();
47
        $this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
48
    }
49
50 View Code Duplication
    private function getFileObject() : SplFileObject
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...
51
    {
52
        $fileObject = new SplFileObject(__DIR__ . '/_files/basic.csv');
53
        $fileObject->setFlags(SplFileObject::READ_CSV);
54
        $fileObject->setCsvControl(',');
55
        return $fileObject;
56
    }
57
58
    private function getStrategy() : ProvidedHeaderStrategy
59
    {
60
        return new ProvidedHeaderStrategy(self::HEADERS);
61
    }
62
}
63