Completed
Pull Request — master (#4)
by Laurens
02:47
created

CsvTest::testRemoveTwoLastLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Tests\Werkspot\BingAdsApiBundle\Api\Helper;
4
5
use PHPUnit_Framework_TestCase;
6
use Werkspot\BingAdsApiBundle\Api\Helper\Csv;
7
8
class CsvTest extends PHPUnit_Framework_TestCase
9
{
10 View Code Duplication
    public function testRemoveOneLastLine()
1 ignored issue
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...
11
    {
12
        $csvArray = $this->getCsvArray();
13
14
        $csvHelper = new Csv();
15
        $result = $csvHelper->removeLastLines($csvArray);
16
17
        $this->assertEquals((count($csvArray) - 1), count($result));
18
    }
19
20 View Code Duplication
    public function testRemoveTwoLastLine()
1 ignored issue
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
        $csvArray = $this->getCsvArray();
23
24
        $csvHelper = new Csv();
25
        $result = $csvHelper->removeLastLines($csvArray, 2);
26
27
        $this->assertEquals((count($csvArray) - 2), count($result));
28
    }
29
30 View Code Duplication
    public function testFixDate()
1 ignored issue
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...
31
    {
32
        $csvArray = [
33
            '"11/11/1988","account_1","1","group 1","1","0","EUR","0.00","Italy","","Bolzano","","Bolzano"',
34
            '"4/22/2007","account_1","2","group 2","4","0","EUR","0.00","Italy","","Milan","","Milan"',
35
        ];
36
        $csvHelper = new Csv();
37
        $result = $csvHelper->convertDateMDYtoYMD($csvArray);
38
39
        $expectedResult = [
40
            "\"1988/11/11\",\"account_1\",\"1\",\"group 1\",\"1\",\"0\",\"EUR\",\"0.00\",\"Italy\",\"\",\"Bolzano\",\"\",\"Bolzano\"\r\n",
41
            "\"2007/04/22\",\"account_1\",\"2\",\"group 2\",\"4\",\"0\",\"EUR\",\"0.00\",\"Italy\",\"\",\"Milan\",\"\",\"Milan\"\r\n",
42
        ];
43
        $this->assertEquals($expectedResult, $result);
44
    }
45
46 View Code Duplication
    public function testRemoveAllHeaders()
1 ignored issue
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
        $csvArray = $this->getCsvArray();
49
        $csvHelper = new Csv();
50
        $result = $csvHelper->removeHeaders($csvArray);
51
52
        $expectedResult = [
53
            '"11/11/1988","account_1","1","group 1","1","0","EUR","0.00","Italy","","Bolzano","","Bolzano"',
54
            '"4/22/2007","account_1","2","group 2","4","0","EUR","0.00","Italy","","Milan","","Milan"',
55
            '',
56
            '"©2016 Microsoft Corporation. All rights reserved. "',
57
        ];
58
        $this->assertEquals($expectedResult, $result);
59
    }
60
61 View Code Duplication
    public function testRemoveFileHeaders()
1 ignored issue
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...
62
    {
63
        $csvArray = $this->getCsvArray();
64
        $csvHelper = new Csv();
65
        $result = $csvHelper->removeHeaders($csvArray, false);
66
67
        $expectedResult = [
68
            '"GregorianDate","AccountName","AdGroupId","AdGroupName","Impressions","Clicks","CurrencyCode","Spend","CountryOrRegion","City","State","MetroArea","MostSpecificLocation"',
69
            '"11/11/1988","account_1","1","group 1","1","0","EUR","0.00","Italy","","Bolzano","","Bolzano"',
70
            '"4/22/2007","account_1","2","group 2","4","0","EUR","0.00","Italy","","Milan","","Milan"',
71
            '',
72
            '"©2016 Microsoft Corporation. All rights reserved. "',
73
        ];
74
        $this->assertEquals($expectedResult, $result);
75
    }
76
77 View Code Duplication
    public function testRemoveAllHeadersInCount()
1 ignored issue
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...
78
    {
79
        $csvArray = $this->getCsvArray();
80
        $csvHelper = new Csv();
81
        $result = $csvHelper->removeHeaders($csvArray);
82
83
        $this->assertEquals((count($csvArray) - 11), count($result));
84
    }
85
86 View Code Duplication
    public function testRemoveFileHeadersAsCount()
1 ignored issue
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...
87
    {
88
        $csvArray = $this->getCsvArray();
89
        $csvHelper = new Csv();
90
        $result = $csvHelper->removeHeaders($csvArray, false);
91
92
        $this->assertEquals((count($csvArray) - 10), count($result));
93
    }
94
95
    public function testArrayToCsvLine()
96
    {
97
        $array = [
98
            'one',
99
            'two',
100
            'three',
101
        ];
102
103
        $csvHelper = new Csv();
104
        $result = $csvHelper->arrayToCsvLine($array);
105
        $this->assertEquals("one,two,three\r\n", $result);
106
107
        $result = $csvHelper->arrayToCsvLine($array, '.', '"');
108
        $this->assertEquals("\"one\".\"two\".\"three\"\r\n", $result);
109
    }
110
111
    private function getCsvArray()
112
    {
113
        return [
114
            '"Report Name: GeoLocationPerformanceReportRequest"',
115
            '"Report Time: 2/28/2016"',
116
            '"Time Zone: (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna"',
117
            '"Last Completed Available Day: 2/29/2016 9:00:00 AM (GMT)"',
118
            '"Last Completed Available Hour: 2/29/2016 9:00:00 AM (GMT)"',
119
            '"Report Aggregation: Daily"',
120
            '"Report Filter: "',
121
            '"Potential Incomplete Data: false"',
122
            '"Rows: 2"',
123
            '',
124
            '"GregorianDate","AccountName","AdGroupId","AdGroupName","Impressions","Clicks","CurrencyCode","Spend","CountryOrRegion","City","State","MetroArea","MostSpecificLocation"',
125
            '"11/11/1988","account_1","1","group 1","1","0","EUR","0.00","Italy","","Bolzano","","Bolzano"',
126
            '"4/22/2007","account_1","2","group 2","4","0","EUR","0.00","Italy","","Milan","","Milan"',
127
            '',
128
            '"©2016 Microsoft Corporation. All rights reserved. "',
129
        ];
130
    }
131
}
132