aboutsummaryrefslogtreecommitdiffstats
path: root/public/system/storage/vendor/cardinity/cardinity-sdk-php/spec/Exception/RequestSpec.php
blob: 7008fe39de5316c9eb3e2534f7ff6497217779b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

namespace spec\Cardinity\Exception;

use Cardinity\Method\Error;
use Cardinity\Method\Payment\Payment;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class RequestSpec extends ObjectBehavior
{
    private $result = [
        'errors' => [
            [
                'field' => 'currency',
                'rejected' => 'EGR',
                'message' => 'invalid or unsupported currency',
            ],
            [
                'field' => 'payment_instrument.exp_month',
                'rejected' => 13,
                'message' => 'must be between 1 and 12',
            ]
        ]
    ];

    private $error;

    function let(\RuntimeException $exception)
    {
        $this->error = new Error();
        $this->error->setErrors($this->result['errors']);

        $this->beConstructedWith(
            $exception,
            $this->error
        );
    }

    function it_should_extend_runtime()
    {
        $this->shouldHaveType('Cardinity\Exception\Runtime');
    }

    function it_stores_previous_exception(\RuntimeException $exception)
    {
        $this->getPrevious()->shouldReturn($exception);
    }

    function it_stores_result()
    {
        $this->getResult()->shouldReturn($this->error);
    }

    function it_should_have_message_containing_response_data()
    {
        $string = 'Response data: ' . serialize($this->error);
        $this->getMessage()->shouldEndWith($string);
    }

    function it_returns_erros_from_error_result_object()
    {
        $this->getErrors()->shouldReturn($this->result['errors']);
    }

    function it_returns_errors_as_string()
    {
        $this
            ->getErrorsAsString()
            ->shouldReturn("currency: invalid or unsupported currency ('EGR' given);
payment_instrument.exp_month: must be between 1 and 12 ('13' given);")
        ;
    }

        function it_returns_erros_from_payment_result_object(\RuntimeException $exception)
    {
        $msg = 'Payment error';

        $payment = new Payment();
        $payment->setError($msg);
        $this->beConstructedWith(
            $exception,
            $payment
        );

        $this->getErrors()->shouldReturn([['field' => 'status', 'message' => $msg]]);
        $this->getErrorsAsString()->shouldReturn("status: Payment error;");
    }

}