aboutsummaryrefslogtreecommitdiffstats
path: root/public/system/storage/vendor/cardinity/cardinity-sdk-php/tests/VoidTest.php
blob: 1c468d9d30c47e3c78fb6257b23c5c0809d5d954 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Cardinity\Tests;

use Cardinity\Method\Void;
use Cardinity\Method\Payment;

class VoidTest extends ClientTestCase
{
    public function testResultObjectSerialization()
    {
        $refund = new Void\Void();
        $refund->setId('foo');
        $refund->setType('bar');
        $refund->setCreated(null);

        $this->assertSame(
            '{"id":"foo","type":"bar"}',
            $refund->serialize()
        );
    }

    public function testResultObjectUnserialization()
    {
        $json = '{"id":"foo","type":"bar"}';

        $payment = new Void\Void();
        $payment->unserialize($json);

        $this->assertSame('foo', $payment->getId());
        $this->assertSame('bar', $payment->getType());
        $this->assertSame(null, $payment->getDescription());
    }

    /**
     * @return Payment\Payment
     */
    public function testCreatePayment()
    {
        $method = new Payment\Create($this->getPaymentParams());
        $payment = $this->client->call($method);

        return $payment;
    }

    /**
     * @depends testCreatePayment
     * @expectedException Cardinity\Exception\Declined
     */
    public function testCreateFail(Payment\Payment $payment)
    {
        $method = new Void\Create(
            $payment->getId(),
            'fail'
        );
        $this->client->call($method);
    }

    /**
     * @depends testCreatePayment
     */
    public function testCreate(Payment\Payment $payment)
    {
        $method = new Void\Create(
            $payment->getId(),
            'my description'
        );
        $result = $this->client->call($method);

        $this->assertInstanceOf('Cardinity\Method\Void\Void', $result); 

        return $result;
    }

    /**
     * @depends testCreate
     */
    public function testGet(Void\Void $void)
    {
        $method = new Void\Get(
            $void->getParentId(),
            $void->getId()
        );
        $result = $this->client->call($method);

        $this->assertInstanceOf('Cardinity\Method\Void\Void', $result); 
        $this->assertSame($void->getParentId(), $result->getParentId());
        $this->assertSame('void', $result->getType());
        $this->assertSame('my description', $result->getDescription());
    }

    /**
     * @depends testCreate
     */
    public function testGetAll(Void\Void $void)
    {
        $method = new Void\GetAll(
            $void->getParentId()
        );
        $result = $this->client->call($method);

        $this->assertInstanceOf('Cardinity\Method\Void\Void', $result[0]); 
        $this->assertSame($void->getId(), $result[0]->getId());
        $this->assertSame($void->getParentId(), $result[0]->getParentId());
    }
}