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

CallbackServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
dl 0
loc 43
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetResponse() 0 15 1
A xmlDummyResponse() 0 3 1
A setUp() 0 5 1
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