CompletePurchaseResponseTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testInvalidHashException() 0 11 1
A testSuccess() 0 21 1
1
<?php
2
/**
3
 * ePayService driver for the Omnipay PHP payment processing library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-epayservice
6
 * @package   omnipay-epayservice
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\ePayService\Message;
12
13
use Omnipay\Tests\TestCase;
14
use Omnipay\Common\Exception\InvalidResponseException;
15
16
class CompletePurchaseResponseTest extends TestCase
17
{
18
    private $request;
19
20
    private $purse                  = 'ec12345';
21
    private $secret                 = '22SAD#-78G8sdf$88';
22
    private $hash                   = 'f974945d5549c760f8f3c9582da49d6e';
23
    private $description            = 'Test Transaction long description';
24
    private $transactionId          = '1SD672345A890sd';
25
    private $transactionReference   = 'sdfa1SD672345A8';
26
    private $amount                 = '1465.01';
27
    private $currency               = 'USD';
28
    private $testMode               = true;
29
30
    public function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
35
        $this->request->initialize([
36
            'purse'     => $this->purse,
37
            'secret'    => $this->secret,
38
            'testMode'  => $this->testMode,
39
        ]);
40
    }
41
42
    public function testInvalidHashException()
43
    {
44
        $this->expectException(InvalidResponseException::class);
45
        $this->expectExceptionMessage('Invalid hash');
46
        new CompletePurchaseResponse($this->request, [
47
            'description'           => $this->description,
48
            'purse'                 => $this->purse,
49
            'secret'                => $this->secret,
50
            'testMode'              => $this->testMode,
51
        ]);
52
    }
53
54
    public function testSuccess()
55
    {
56
        $response = new CompletePurchaseResponse($this->request, [
57
            'testMode'              => $this->testMode,
58
            'check_key'             => $this->hash,
59
            'EPS_DESCRIPTION'       => $this->description,
60
            'EPS_GUID'              => $this->purse,
61
            'EPS_AMOUNT'            => $this->amount,
62
            'EPS_TRID'              => $this->transactionId,
63
            'EPS_ACCNUM'            => $this->transactionReference,
64
            'EPS_CURRENCY'          => $this->currency,
65
            'EPS_RESULT'            => 'done'
66
        ]);
67
68
        $this->assertTrue($response->isSuccessful());
69
        $this->assertSame($this->transactionId,         $response->getTransactionId());
70
        $this->assertSame($this->transactionReference,  $response->getTransactionReference());
71
        $this->assertSame($this->amount,                $response->getAmount());
72
        $this->assertSame($this->hash,                  $response->getHash());
73
        $this->assertSame($this->currency,              $response->getCurrency());
74
    }
75
}
76