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

CompletePurchaseResponseTest::testSignException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
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\CompletePurchaseRequest;
15
use Omnipay\InterKassa\Message\CompletePurchaseResponse;
16
use Omnipay\InterKassa\Stubs\CompletePurchaseResponseStub;
17
use Omnipay\Tests\TestCase;
18
use Symfony\Component\HttpFoundation\Request as HttpRequest;
19
20 View Code Duplication
class CompletePurchaseResponseTest extends 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...
21
{
22
    /**
23
     * @var CompletePurchaseResponseStub
24
     */
25
    protected $stub;
26
27
    public function setUp()
28
    {
29
        parent::setUp();
30
31
        $this->stub = new CompletePurchaseResponseStub();
32
    }
33
34
    /**
35
     * @param array $options
36
     * @return CompletePurchaseRequest
37
     */
38
    public function createRequest($options = [])
39
    {
40
        $stub = $this->stub;
41
42
        $httpRequest = new HttpRequest([], array_merge([
43
            'ik_co_id' => $stub->purse,
44
            'ik_pm_no' => $stub->payment_no,
45
            'ik_desc' => $stub->description,
46
            'ik_pw_via' => $stub->payway,
47
            'ik_am' => $stub->amount,
48
            'ik_cur' => $stub->currency,
49
            'ik_inv_id' => $stub->transactionId,
50
            'ik_inv_st' => $stub->state,
51
            'ik_inv_prc' => $stub->time,
52
            'ik_sign' => $stub->sign,
53
        ], $options));
54
55
        $request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
56
        $request->initialize([
57
            'signAlgorithm' => $stub->signAlgorithm,
58
            'signKey' => $stub->signKey,
59
        ]);
60
61
        return $request;
62
    }
63
64
    public function testSignException()
65
    {
66
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Failed to validate signature');
67
        $this->createRequest(['ik_wtf' => ':)'])->send();
68
    }
69
70
    public function testStateException()
71
    {
72
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'The payment was not success');
73
        $this->createRequest(['ik_inv_st' => 'fail', 'ik_sign' => 'ElWhUp/CjjSXF0ZjNIKbOk+WjpQ9/KIeowD0TjTshw0='])->send();
74
    }
75
76
    public function testSuccess()
77
    {
78
        /** @var CompletePurchaseResponse $response */
79
        $response = $this->createRequest()->send();
80
        $stub = $this->stub;
81
82
        $this->assertTrue($response->isSuccessful());
83
        $this->assertSame($stub->purse, $response->getCheckoutId());
84
        $this->assertSame($stub->payment_no, $response->getTransactionId());
85
        $this->assertSame($stub->transactionId, $response->getTransactionReference());
86
        $this->assertSame($stub->amount, $response->getAmount());
87
        $this->assertSame($stub->currency, $response->getCurrency());
88
        $this->assertSame($stub->timestamp, $response->getTime());
89
        $this->assertSame($stub->payway, $response->getPayer());
90
        $this->assertSame($stub->state, $response->getState());
91
        $this->assertSame($stub->sign, $response->getSign());
92
    }
93
}
94