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

ProvidedHeaderStrategyTest::createDataRow()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 19

Duplication

Lines 25
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 25
loc 25
rs 8.8571
cc 1
eloc 19
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 View Code Duplication
    public function rowIsNotHeaderRow()
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...
43
    {
44
        $strategy = $this->getStrategy();
45
        $fileObject = $this->getFileObject();
46
        $fileObject->fgetcsv();
47
        $this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
48
    }
49
50
    /**
51
     * @test
52
     * @covers ::createDataRow
53
     */
54 View Code Duplication
    public function createDataRow()
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...
55
    {
56
        $row = [
57
            'bk101',
58
            'Gambardella, Matthew',
59
            'XML Developer\'s Guide',
60
            'Computer',
61
            '44.95',
62
            '2000-10-01',
63
            'An in-depth look at creating applications with XML.',
64
        ];
65
        $strategy = $this->getStrategy();
66
        $this->assertSame(
67
            [
68
                'id' => 'bk101',
69
                'author' => 'Gambardella, Matthew',
70
                'title' => 'XML Developer\'s Guide',
71
                'genre' => 'Computer',
72
                'price' => '44.95',
73
                'publish_date' => '2000-10-01',
74
                'description' => 'An in-depth look at creating applications with XML.',
75
            ],
76
            $strategy->createDataRow($row)
77
        );
78
    }
79
80 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...
81
    {
82
        $fileObject = new SplFileObject(__DIR__ . '/_files/basic.csv');
83
        $fileObject->setFlags(SplFileObject::READ_CSV);
84
        $fileObject->setCsvControl(',');
85
        return $fileObject;
86
    }
87
88
    private function getStrategy() : ProvidedHeaderStrategy
89
    {
90
        return new ProvidedHeaderStrategy(self::HEADERS);
91
    }
92
}
93