GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DirectLinkQueryResponseTest::provideXML()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * @author Nicolas Clavaud <[email protected]>
4
 */
5
6
namespace Ogone\Tests\DirectLink;
7
8
use Ogone\DirectLink\DirectLinkQueryResponse;
9
10 View Code Duplication
class DirectLinkQueryResponseTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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
13
    /**
14
     * @test
15
     * @expectedException InvalidArgumentException
16
     */
17
    public function CantExistWithoutXmlFile()
18
    {
19
        $queryResponse = new DirectLinkQueryResponse('');
0 ignored issues
show
Unused Code introduced by
$queryResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
    }
21
22
    /** @test */
23
    public function ParametersCanBeRetrieved()
24
    {
25
        $xml = $this->provideXML();
26
27
        $queryResponse = new DirectLinkQueryResponse($xml);
28
        $this->assertEquals('5', $queryResponse->getParam('orderid'));
29
    }
30
31
    /**
32
     * @test
33
     * @expectedException InvalidArgumentException
34
     */
35
    public function RequestIsFilteredFromNonOgoneParameters()
36
    {
37
        $xml = $this->provideXML();
38
39
        $queryResponse = new DirectLinkQueryResponse($xml);
40
        $queryResponse->getParam('unknown_param');
41
    }
42
43
    /**
44
     * @test
45
     * @expectedException InvalidArgumentException
46
     */
47
    public function ChecksInvalidXml()
48
    {
49
        $xml = $this->provideInvalidXML();
50
51
        $queryResponse = new DirectLinkQueryResponse($xml);
0 ignored issues
show
Unused Code introduced by
$queryResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
52
    }
53
54
    /** @test */
55
    public function ChecksStatus()
56
    {
57
        $xml = $this->provideXML();
58
59
        $queryResponse = new DirectLinkQueryResponse($xml);
60
        $this->assertTrue($queryResponse->isSuccessful());
61
    }
62
63
    /** @test */
64
    public function AmountIsConvertedToCent()
65
    {
66
        $xml = $this->provideXML();
67
68
        $queryResponse = new DirectLinkQueryResponse($xml);
69
        $this->assertEquals(450, $queryResponse->getParam('amount'));
70
    }
71
72
    public function provideFloats()
73
    {
74
        return array(
75
            array('17.89', 1789),
76
            array('65.35', 6535),
77
            array('12.99', 1299),
78
        );
79
    }
80
81
    /**
82
     * @test
83
     * @dataProvider provideFloats
84
     */
85
    public function CorrectlyConvertsFloatAmountsToInteger($string, $integer)
86
    {
87
        $xml = $this->provideXML($string);
88
89
        $queryResponse = new DirectLinkQueryResponse($xml);
90
        $this->assertEquals($integer, $queryResponse->getParam('amount'));
91
    }
92
93
    /**
94
     * Helper method to setup an xml-string
95
     */
96
    private function provideXML($amount = null)
97
    {
98
99
        $xml = '<?xml version="1.0"?>
100
                <ncresponse
101
                orderID="5"
102
                PAYID="33146134"
103
                PAYIDSUB=""
104
                NCSTATUS="0"
105
                NCERROR="0"
106
                NCERRORPLUS="!"
107
                ACCEPTANCE="test123"
108
                STATUS="91"
109
                ECI="7"
110
                AMOUNT="'.(($amount) ? $amount : '4.5').'"
111
                CURRENCY="GBP"
112
                PM="CreditCard"
113
                BRAND="VISA"
114
                CARDNO="XXXXXXXXXXXX1111"
115
                IP="127.0.0.1">
116
                </ncresponse>';
117
118
        return $xml;
119
    }
120
121
    /**
122
     * Helper method to setup an invalid xml-string
123
     */
124
    private function provideInvalidXML()
125
    {
126
        $xml = '<?xml version="1.0"?>
127
                <ncresponse
128
                </ncresponse>';
129
130
        return $xml;
131
    }
132
}
133