Completed
Push — master ( 380a6c...a8d4ee )
by Robin
9s
created

ParseTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 20.83 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 15
loc 72
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testParseStatementBank() 0 6 1
A testParsesAllFoundStatements() 15 15 1
A testHandleEntryYearRollover() 0 20 1
A testIssue48() 0 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Abn;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine\Abn;
6
7
/**
8
 *
9
 */
10
class ParseTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Abn
14
     */
15
    private $engine;
16
17
    protected function setUp()
18
    {
19
        $this->engine = new Abn();
20
        $this->engine->loadString(file_get_contents(__DIR__.'/sample'));
21
    }
22
23
    public function testParseStatementBank()
24
    {
25
        $method = new \ReflectionMethod($this->engine, 'parseStatementBank');
26
        $method->setAccessible(true);
27
        $this->assertEquals('ABN', $method->invoke($this->engine));
28
    }
29
30 View Code Duplication
    public function testParsesAllFoundStatements()
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...
31
    {
32
        $statements = $this->engine->parse();
33
34
        $this->assertCount(4, $statements);
35
        $first = $statements[0];
36
        $last = end($statements);
37
38
        $this->assertEquals('23-06-2009', $first->getStartTimestamp('d-m-Y'));
39
        $this->assertEquals('24-06-2009', $first->getEndTimestamp('d-m-Y'));
40
        $this->assertEquals(210.5, $first->getDeltaPrice());
41
42
        $this->assertEquals('23-06-2009', $last->getStartTimestamp('d-m-Y'));
43
        $this->assertEquals('24-06-2009', $last->getEndTimestamp('d-m-Y'));
44
    }
45
46
    public function testHandleEntryYearRollover()
47
    {
48
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
49
        $statements = $this->engine->parse();
50
51
        $this->assertCount(1, $statements);
52
        list($sameday, $nextDay, $nextMonth, $nextYear) = $statements[0]->getTransactions();
53
54
        $this->assertEquals('01-01-2009', $sameday->getValueTimestamp('d-m-Y'));
55
        $this->assertEquals('01-01-2009', $sameday->getEntryTimestamp('d-m-Y'));
56
57
        $this->assertEquals('01-01-2009', $nextDay->getValueTimestamp('d-m-Y'));
58
        $this->assertEquals('02-01-2009', $nextDay->getEntryTimestamp('d-m-Y'));
59
60
        $this->assertEquals('01-01-2009', $nextMonth->getValueTimestamp('d-m-Y'));
61
        $this->assertEquals('01-02-2009', $nextMonth->getEntryTimestamp('d-m-Y'));
62
63
        $this->assertEquals('31-12-2009', $nextYear->getValueTimestamp('d-m-Y'));
64
        $this->assertEquals('01-01-2010', $nextYear->getEntryTimestamp('d-m-Y'));
65
    }
66
67
    public function testIssue48()
68
    {
69
        $this->engine->loadString(file_get_contents(__DIR__.'/issue48'));
70
        $statements = $this->engine->parse();
71
72
        $this->assertCount(1, $statements);
73
        $transactions = $statements[0]->getTransactions();
74
75
        $this->assertEquals('15-12-2016', $transactions[0]->getValueTimestamp('d-m-Y'));
76
        $this->assertEquals('15-12-2016', $transactions[0]->getEntryTimestamp('d-m-Y'));
77
78
        $this->assertEquals('15-12-2016', $transactions[1]->getValueTimestamp('d-m-Y'));
79
        $this->assertEquals('15-12-2016', $transactions[1]->getEntryTimestamp('d-m-Y'));
80
    }
81
}
82