1 | <?php |
||
8 | class CsvTest extends PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | public function testRemoveOneLastLine() |
||
1 ignored issue
–
show
|
|||
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 | public function testRemoveTwoLastLine() |
||
1 ignored issue
–
show
|
|||
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 | public function testFixDate() |
||
1 ignored issue
–
show
|
|||
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 | public function testRemoveAllHeaders() |
||
1 ignored issue
–
show
|
|||
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 | public function testRemoveFileHeaders() |
||
1 ignored issue
–
show
|
|||
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 | public function testRemoveAllHeadersInCount() |
||
1 ignored issue
–
show
|
|||
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 | public function testRemoveFileHeadersAsCount() |
||
1 ignored issue
–
show
|
|||
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() |
||
110 | |||
111 | private function getCsvArray() |
||
131 | } |
||
132 |
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.