GatewayTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 71
rs 10
c 3
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testCompletePurchaseRequest() 0 7 1
A testIsActive() 0 19 1
A testPurchaseResponse() 0 26 1
1
<?php
2
3
namespace ByTIC\Payments\Tests\Gateways\Providers\Romcard;
4
5
use Paytic\Omnipay\Romcard\Message\PurchaseResponse;
6
use ByTIC\Payments\Gateways\Providers\Romcard\Gateway;
7
use ByTIC\Payments\Gateways\Providers\Romcard\Message\CompletePurchaseRequest;
8
use Paytic\Omnipay\Romcard\Message\SaleRequest;
9
use Paytic\Payments\Tests\Gateways\GatewayTest as AbstractGatewayTest;
10
use ByTIC\Payments\Tests\Fixtures\Records\Gateways\Providers\Romcard\RomcardData;
11
use Paytic\Payments\Tests\Fixtures\Records\PaymentMethods\PaymentMethod;
12
use Http\Discovery\Psr17FactoryDiscovery;
13
14
/**
15
 * Class GatewayTest
16
 * @package ByTIC\Payments\Tests\Gateways\Providers\Romcard
17
 */
18
class GatewayTest extends AbstractGatewayTest
19
{
20
    public function testPurchaseResponse()
21
    {
22
        //        Debug::debug($this->gateway->getParameters());
23
        $request = $this->gateway->purchaseFromModel($this->purchase);
24
25
        /** @var PurchaseResponse $response */
26
//        Debug::debug($request->getParameters());
27
        $response = $request->send();
28
        self::assertInstanceOf(PurchaseResponse::class, $response);
29
30
        $data = $response->getRedirectData();
31
        self::assertSame('000000060001099', $data['MERCHANT']);
32
33
        $gatewayResponse = $this->client->request(
34
            'POST',
35
            $response->getRedirectUrl(),
36
            ['Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'],
37
            Psr17FactoryDiscovery::findStreamFactory()->createStream(http_build_query($data, '', '&'))
38
        );
39
        self::assertSame(200, $gatewayResponse->getStatusCode());
40
41
        //Validate first Response
42
        $body = $gatewayResponse->getBody()->__toString();
43
44
        self::assertMatchesRegularExpression('/Tranzactie Aprobata/', $body);
0 ignored issues
show
Bug introduced by
The method assertMatchesRegularExpression() does not exist on ByTIC\Payments\Tests\Gat...ers\Romcard\GatewayTest. ( Ignorable by Annotation )

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

44
        self::/** @scrutinizer ignore-call */ 
45
              assertMatchesRegularExpression('/Tranzactie Aprobata/', $body);

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...
45
        self::assertMatchesRegularExpression('/value="Aproba" name="SEND_BUTTON"/', $body);
46
    }
47
48
    public function testCompletePurchaseRequest()
49
    {
50
        /** @var CompletePurchaseRequest $request */
51
        $request = $this->gateway->completePurchase([]);
52
53
        self::assertInstanceOf(CompletePurchaseRequest::class, $request);
54
        self::assertInstanceOf(SaleRequest::class, $request->getSaleRequest());
55
    }
56
57
    public function testIsActive()
58
    {
59
        $gateway = new Gateway();
60
        self::assertFalse($gateway->isActive());
61
62
        $gateway->setTerminal('999999');
63
        $gateway->setKey('999999');
64
        $gateway->setMerchantName('999999');
65
        $gateway->setMerchantEmail('999999');
66
67
        self::assertFalse($gateway->isActive());
68
69
        $gateway->setMerchantUrl('9');
70
71
        self::assertFalse($gateway->isActive());
72
73
        $gateway->setMerchantUrl('999999');
74
75
        self::assertTrue($gateway->isActive());
76
    }
77
78
    protected function setUp() : void
79
    {
80
        parent::setUp();
81
82
        /** @var PaymentMethod $paymentMethod */
83
        $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 Paytic\Payments\Tests\Fi...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...
84
        $paymentMethod->options = trim(RomcardData::getMethodOptions());
85
86
        $this->purchase->created = date('Y-m-d H:i:s');
87
88
        $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 or Omnipay\Common\GatewayInterface is incompatible with the declared type ByTIC\Common\Payments\Gateways\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...
89
    }
90
}
91