Passed
Push — master ( ff7474...c002dd )
by Gabriel
05:50
created

getNewResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Tests\Gateways\Providers\PlatiOnline\Message;
4
5
use ByTIC\Payments\Gateways\Providers\PlatiOnline\Message\ServerCompletePurchaseRequest;
6
use ByTIC\Payments\Gateways\Providers\PlatiOnline\Message\ServerCompletePurchaseResponse;
7
use ByTIC\Payments\Tests\AbstractTest;
8
use ByTIC\Payments\Tests\Fixtures\Records\Purchases\PurchasableRecord;
9
use ByTIC\Payments\Tests\Fixtures\Records\Purchases\PurchasableRecordManager;
10
use ByTIC\Payments\Tests\Gateways\Providers\AbstractGateway\Message\ServerCompletePurchaseResponseTrait;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Class ServerCompletePurchaseResponseTest
15
 * @package ByTIC\Payments\Tests\Gateways\Providers\PlatiOnline\Message
16
 */
17
class ServerCompletePurchaseResponseTest extends AbstractTest
18
{
19
    use ServerCompletePurchaseResponseTrait;
20
21
    public function testResponseForValidTransaction()
22
    {
23
        $httpRequest = $this->generateRequestFromFixtures(
24
            TEST_FIXTURE_PATH . '/requests/platiOnline/serverCompletePurchase/basicParams.php'
25
        );
26
27
        $model = \Mockery::mock(PurchasableRecord::class)->makePartial();
28
        $model->shouldReceive('getPaymentGateway')->andReturn(null);
29
30
        $modelManager = \Mockery::mock(PurchasableRecordManager::class)->makePartial();
31
        $modelManager->shouldReceive('findOne')->andReturn($model);
32
33
        $request = new ServerCompletePurchaseRequest($this->client, $httpRequest);
34
        $request->initialize($this->gatewayParams());
35
        $request->setModelManager($modelManager);
36
37
        $response = $request->send();
38
        self::assertInstanceOf(ServerCompletePurchaseResponse::class, $response);
39
        self::assertInstanceOf(PurchasableRecord::class, $response->getModel());
0 ignored issues
show
Bug introduced by
The method getModel() does not exist on ByTIC\Omnipay\PlatiOnlin...ompletePurchaseResponse. Did you maybe mean getCode()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        self::assertInstanceOf(PurchasableRecord::class, $response->/** @scrutinizer ignore-call */ getModel());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        self::assertSame(false, $response->isCancelled());
41
        self::assertSame(false, $response->isPending());
42
        self::assertSame('active', $response->getModelResponseStatus());
0 ignored issues
show
introduced by
The method getModelResponseStatus() does not exist on ByTIC\Omnipay\PlatiOnlin...ompletePurchaseResponse. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        self::assertSame('active', $response->/** @scrutinizer ignore-call */ getModelResponseStatus());
Loading history...
43
44
        $sessionDebug = $response->getSessionDebug();
0 ignored issues
show
introduced by
The method getSessionDebug() does not exist on ByTIC\Omnipay\PlatiOnlin...ompletePurchaseResponse. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        /** @scrutinizer ignore-call */ 
45
        $sessionDebug = $response->getSessionDebug();
Loading history...
45
        self::assertArrayHasKey('order', $sessionDebug);
46
        self::assertArrayHasKey('transaction', $sessionDebug);
47
48
        $content = $response->getContent();
49
        self::assertSame('<?xml version="1.0" encoding="UTF-8" ?><itsn><x_trans_id>6917422</x_trans_id><merchServerStamp>' . date("Y-m-d H:m:s") . '</merchServerStamp><f_response_code>1</f_response_code></itsn>', $content);
50
    }
51
52
    /**
53
     * @return ServerCompletePurchaseResponse
54
     */
55
    protected function getNewResponse()
56
    {
57
        $request = new ServerCompletePurchaseRequest($this->client, new Request());
58
59
        return new ServerCompletePurchaseResponse($request, []);
60
    }
61
62
    protected function gatewayParams()
63
    {
64
        return [
65
            'loginId' => getenv('PLATIONLINE_LOGIN_ID'),
66
            'publicKey' => getenv('PLATIONLINE_PUBLIC_KEY'),
67
            'privateKey' => getenv('PLATIONLINE_PRIVATE_KEY'),
68
            'website' => getenv('PLATIONLINE_WEBSITE'),
69
            'initialVector' => getenv('PLATIONLINE_INITIAL_VECTOR'),
70
            'initialVectorItsn' => getenv('PLATIONLINE_INITIAL_VECTOR_ITSN'),
71
            'testMode' => true
72
        ];
73
    }
74
}
75