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

testServerCompletePurchaseConfirmedResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Tests\Gateways\Providers\Librapay;
4
5
use ByTIC\Omnipay\Librapay\Message\ServerCompletePurchaseResponse;
6
use ByTIC\Payments\Gateways\Providers\Librapay\Gateway;
7
use ByTIC\Payments\Tests\Fixtures\Records\Gateways\Providers\Librapay\LibrapayData;
8
use ByTIC\Payments\Tests\Fixtures\Records\PaymentMethods\PaymentMethod;
9
use ByTIC\Payments\Tests\Gateways\Providers\AbstractGateway\GatewayTest as AbstractGatewayTest;
10
11
/**
12
 * Class GatewayTest
13
 * @package ByTIC\Payments\Tests\Gateways\Providers\Librapay
14
 */
15
class GatewayTest extends AbstractGatewayTest
16
{
17
    public function testIsActive()
18
    {
19
        $gateway = new Gateway();
20
        self::assertFalse($gateway->isActive());
21
22
        $gateway->setMerchant('999999');
23
        $gateway->setTerminal('999999');
24
        $gateway->setKey('999999');
25
        $gateway->setMerchantName('999999');
26
        $gateway->setMerchantEmail('999999');
27
28
        self::assertFalse($gateway->isActive());
29
30
        $gateway->setMerchantUrl('9');
31
32
        self::assertFalse($gateway->isActive());
33
34
        $gateway->setMerchantUrl('999999');
35
36
        self::assertTrue($gateway->isActive());
37
    }
38
39
    public function testServerCompletePurchaseConfirmedResponse()
40
    {
41
        $httpRequest = LibrapayData::getServerCompletePurchaseRequest();
42
        $response = $this->createServerCompletePurchaseResponse($httpRequest);
43
44
        self::assertTrue($response->isSuccessful());
45
46
        $content = $response->getContent();
47
        self::assertSame('1', $content);
48
    }
49
50
    /**
51
     * @param $request
52
     * @return ServerCompletePurchaseResponse
53
     */
54
    protected function createServerCompletePurchaseResponse($request)
55
    {
56
        /** @var ServerCompletePurchaseResponse $response */
57
        $response = $this->gatewayManager->detectItemFromHttpRequest(
58
            $this->purchaseManager,
59
            'serverCompletePurchase',
60
            $request
61
        );
62
63
        self::assertInstanceOf(ServerCompletePurchaseResponse::class, $response);
64
65
        return $response;
66
    }
67
68
    protected function setUp(): void
69
    {
70
        parent::setUp();
71
72
        /** @var PaymentMethod $paymentMethod */
73
        $paymentMethod = $this->purchase->getPaymentMethod();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $paymentMethod is correct as $this->purchase->getPaymentMethod() targeting ByTIC\Payments\Tests\Fix...ord::getPaymentMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
        $paymentMethod->options = trim(LibrapayData::getMethodOptions());
75
76
        $this->purchase->created = date('Y-m-d H:i:s');
77
78
        $this->gateway = $paymentMethod->getType()->getGateway();
0 ignored issues
show
Documentation Bug introduced by
It seems like $paymentMethod->getType()->getGateway() of type ByTIC\Payments\Gateways\...way\Traits\GatewayTrait is incompatible with the declared type ByTIC\Common\Payments\Ga...AbstractGateway\Gateway of property $gateway.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Bug introduced by
The method getGateway() does not exist on ByTIC\Payments\Models\Methods\Types\AbstractType. It seems like you code against a sub-type of ByTIC\Payments\Models\Methods\Types\AbstractType such as ByTIC\Payments\Models\Methods\Types\CreditCards. ( Ignorable by Annotation )

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

78
        $this->gateway = $paymentMethod->getType()->/** @scrutinizer ignore-call */ getGateway();
Loading history...
79
    }
80
}
81