Completed
Push — master ( 1b7afa...9fbca5 )
by Dmitry
03:33
created

OldCompletePurchaseResponseTest::testSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
/*
4
 * InterKassa driver for the Omnipay PHP payment processing library
5
 *
6
 * @link      https://github.com/hiqdev/omnipay-interkassa
7
 * @package   omnipay-interkassa
8
 * @license   MIT
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace Omnipay\InterKassa\Tests\Message;
13
14
use Omnipay\InterKassa\Message\OldCompletePurchaseRequest;
15
use Omnipay\InterKassa\Message\OldCompletePurchaseResponse;
16
use Omnipay\InterKassa\Stubs\OldCompletePurchaseResponseStub;
17
use Symfony\Component\HttpFoundation\Request as HttpRequest;
18
19 View Code Duplication
class OldCompletePurchaseResponseTest extends CompletePurchaseResponseTest
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...
20
{
21
    /**
22
     * @var OldCompletePurchaseResponseStub
23
     */
24
    protected $stub;
25
26
    public function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->stub = new OldCompletePurchaseResponseStub();
31
    }
32
33
    /**
34
     * @param array $options
35
     * @return OldCompletePurchaseRequest
36
     */
37
    public function createRequest($options = [])
38
    {
39
        $stub = $this->stub;
40
41
        $httpRequest = new HttpRequest([], array_merge([
42
            'ik_shop_id' => $stub->purse,
43
            'ik_payment_id' => $stub->payment_no,
44
            'ik_payment_desc' => $stub->description,
45
            'ik_payment_amount' => $stub->amount,
46
            'ik_payment_timestamp' => $stub->time,
47
            'ik_sign_hash' => $stub->sign,
48
            'ik_payment_state' => $stub->state,
49
            'ik_trans_id' => $stub->transactionId,
50
            'ik_paysystem_alias' => $stub->payway,
51
52
        ], $options));
53
54
        $request = new OldCompletePurchaseRequest($this->getHttpClient(), $httpRequest);
55
        $request->initialize([
56
            'signAlgorithm' => $stub->signAlgorithm,
57
            'signKey' => $stub->signKey,
58
        ]);
59
60
        return $request;
61
    }
62
63
    public function testSignException()
64
    {
65
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Failed to validate signature');
66
        $this->createRequest(['ik_wtf' => ':)'])->send();
67
    }
68
69
    public function testStateException()
70
    {
71
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'The payment was not success');
72
        $this->createRequest(['ik_payment_state' => 'fail', 'ik_sign_hash' => 'IL/KyMotmW5XeL2g86kYGlVJXOYTO+HAsuSzudI0qHE='])->send();
73
    }
74
75
    public function testSuccess()
76
    {
77
        /** @var OldCompletePurchaseResponse $response */
78
        $response = $this->createRequest()->send();
79
        $stub = $this->stub;
80
81
        $this->assertTrue($response->isSuccessful());
82
        $this->assertSame($stub->purse, $response->getCheckoutId());
83
        $this->assertSame($stub->payment_no, $response->getTransactionId());
84
        $this->assertSame($stub->transactionId, $response->getTransactionReference());
85
        $this->assertSame($stub->amount, $response->getAmount());
86
        $this->assertSame($stub->currency, $response->getCurrency());
87
        $this->assertSame($stub->timestamp, $response->getTime());
88
        $this->assertSame($stub->payway, $response->getPayer());
89
        $this->assertSame($stub->state, $response->getState());
90
        $this->assertSame($stub->sign, $response->getSign());
91
    }
92
}
93