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.

CorrectlyConvertsFloatAmountsToInteger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Marlon Ogone package.
5
 *
6
 * (c) Marlon BVBA <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ogone\Tests\Ecommerce;
13
14
use Ogone\PaymentResponse;
15
use Ogone\Tests\ShaComposer\FakeShaComposer;
16
use Ogone\Ecommerce\EcommercePaymentResponse;
17
use InvalidArgumentException;
18
19
class EcommercePaymentResponseTest extends \PHPUnit_Framework_TestCase
20
{
21
    /** @test */
22
    public function CanBeVerified()
23
    {
24
        $aRequest = $this->provideRequest();
25
26
        $paymentResponse = new EcommercePaymentResponse($aRequest);
27
        $this->assertTrue($paymentResponse->isValid(new FakeShaComposer));
28
    }
29
30
    /** @test */
31
    public function CanBeConvertedToArray()
32
    {
33
        $aRequest = $this->provideRequest();
34
35
        $paymentResponse = new EcommercePaymentResponse($aRequest);
36
        $paymentResponse->isValid(new FakeShaComposer);
37
        $array = $paymentResponse->toArray();
38
        $this->assertArrayHasKey('ORDERID', $array);
39
        $this->assertArrayHasKey('STATUS', $array);
40
        $this->assertArrayHasKey('AMOUNT', $array);
41
        $this->assertArrayHasKey('SHASIGN', $array);
42
    }
43
44
45
    /**
46
     * @test
47
     * @expectedException InvalidArgumentException
48
    */
49
    public function CannotExistWithoutShaSign()
50
    {
51
        $paymentResponse = new EcommercePaymentResponse(array());
0 ignored issues
show
Unused Code introduced by
$paymentResponse 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 View Code Duplication
    public function ParametersCanBeRetrieved()
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...
56
    {
57
        $aRequest = $this->provideRequest();
58
59
        $paymentResponse = new EcommercePaymentResponse($aRequest);
60
        $this->assertEquals($aRequest['orderID'], $paymentResponse->getParam('orderid'));
61
    }
62
63
    /**
64
     * @test
65
     * @expectedException InvalidArgumentException
66
     */
67
    public function RequestIsFilteredFromNonOgoneParameters()
68
    {
69
        $aRequest = $this->provideRequest();
70
71
        $paymentResponse = new EcommercePaymentResponse($aRequest);
72
        $paymentResponse->getParam('unknown_param');
73
    }
74
75
    /** @test */
76
    public function ChecksStatus()
77
    {
78
        $aRequest = $this->provideRequest();
79
80
        $paymentResponse = new EcommercePaymentResponse($aRequest);
81
        $this->assertTrue($paymentResponse->isSuccessful());
82
    }
83
84
    /** @test */
85
    public function AmountIsConvertedToCent()
86
    {
87
        $aRequest = $this->provideRequest();
88
89
        $paymentResponse = new EcommercePaymentResponse($aRequest);
90
        $this->assertEquals(100, $paymentResponse->getParam('amount'));
91
    }
92
93
    public function provideFloats()
94
    {
95
        return array(
96
            array('17.89', 1789),
97
            array('65.35', 6535),
98
            array('12.99', 1299),
99
            array('1.0', 100)
100
        );
101
    }
102
103
    /**
104
     * @test
105
     * @expectedException InvalidArgumentException
106
     */
107
    public function InvalidForInvalidCurrency()
108
    {
109
        $paymentResponse = new EcommercePaymentResponse(array('amount' => 'NaN', 'shasign' => '123'));
110
        $paymentResponse->getParam('amount');
111
    }
112
113
    /**
114
     * @test
115
     * @dataProvider provideFloats
116
     */
117
    public function CorrectlyConvertsFloatAmountsToInteger($string, $integer)
118
    {
119
        $paymentResponse = new EcommercePaymentResponse(array('amount' => $string, 'shasign' => '123'));
120
        $this->assertEquals($integer, $paymentResponse->getParam('amount'));
121
    }
122
123
    /**
124
     * Helper method to setup a request array
125
     */
126
    private function provideRequest()
127
    {
128
        return array(
129
            'orderID' => '123',
130
            'SHASIGN' => FakeShaComposer::FAKESHASTRING,
131
            'UNKNOWN_PARAM' => false, /* unkown parameter, should be filtered out */
132
            'status' => PaymentResponse::STATUS_AUTHORISED,
133
            'amount' => 1,
134
        );
135
    }
136
}
137