Passed
Branch refactoring (232535)
by João Felipe Magro
01:20
created

CallbackServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tests\Classes\Services;
4
5
use Ipag\Classes\Services\CallbackService;
6
use PHPUnit\Framework\TestCase;
7
use stdClass;
8
9
class CallbackServiceTest extends TestCase
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        $this->callbackService = new CallbackService();
0 ignored issues
show
Bug Best Practice introduced by
The property callbackService does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
    }
17
18
    private function xmlDummyResponse()
19
    {
20
        return '<?xml version="1.0" encoding="utf-8" ?>
21
            <retorno>
22
                <id_transacao>123456789</id_transacao>
23
                <valor>10.00</valor>
24
                <num_pedido>123456</num_pedido>
25
                <status_pagamento>8</status_pagamento>
26
                <mensagem_transacao>Transação Autorizada</mensagem_transacao>
27
                <metodo>visa</metodo>
28
                <operadora>cielo</operadora>
29
                <operadora_mensagem>Transação autorizada</operadora_mensagem>
30
                <id_librepag>12345</id_librepag>
31
                <autorizacao_id>123456</autorizacao_id>
32
                <redirect>false</redirect>
33
                <url_autenticacao>https://minhaloja.com.br/ipag/retorno</url_autenticacao>
34
            </retorno>';
35
    }
36
37
    public function testGetResponse()
38
    {
39
        $expected = new stdClass();
40
        $expected->tid = '123456789';
41
        $expected->amount = 10.00;
42
43
        $expected->payment = new stdClass();
44
        $expected->payment->status = '8';
45
46
        $response = $this->callbackService->getResponse($this->xmlDummyResponse());
47
48
        $this->assertInstanceOf('stdClass', $response);
49
        $this->assertEquals($expected->tid, $response->tid);
50
        $this->assertEquals($expected->amount, $response->amount);
51
        $this->assertEquals($expected->payment->status, $response->payment->status);
52
    }
53
}
54