1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Synchronizer; |
4
|
|
|
|
5
|
|
|
use Loevgaard\AltaPay\Client; |
6
|
|
|
use Loevgaard\AltaPay\Response\GetTerminals; |
7
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Terminal; |
8
|
|
|
use Loevgaard\DandomainAltapayBundle\Manager\TerminalManager; |
9
|
|
|
use Loevgaard\DandomainAltapayBundle\Synchronizer\TerminalSynchronizer; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Psr\Http\Message\ResponseInterface; |
12
|
|
|
|
13
|
|
|
class TerminalSynchronizerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testSyncAll() |
16
|
|
|
{ |
17
|
|
|
$xml = <<<XML |
18
|
|
|
<?xml version="1.0"?> |
19
|
|
|
<APIResponse version="20170228"> |
20
|
|
|
<Header> |
21
|
|
|
<Date>2016-01-07T23:43:20+01:00</Date> |
22
|
|
|
<Path>API/getTerminals</Path> |
23
|
|
|
<ErrorCode>0</ErrorCode> |
24
|
|
|
<ErrorMessage></ErrorMessage> |
25
|
|
|
</Header> |
26
|
|
|
<Body> |
27
|
|
|
<Result>Success</Result> |
28
|
|
|
<Terminals> |
29
|
|
|
<Terminal> |
30
|
|
|
<Title>AltaPay Multi-Nature Terminal</Title> |
31
|
|
|
<Country>DK</Country> |
32
|
|
|
<Natures> |
33
|
|
|
<Nature>CreditCard</Nature> |
34
|
|
|
<Nature>EPayment</Nature> |
35
|
|
|
<Nature>IdealPayment</Nature> |
36
|
|
|
<Nature>Invoice</Nature> |
37
|
|
|
</Natures> |
38
|
|
|
<Currencies> |
39
|
|
|
<Currency>DKK</Currency> |
40
|
|
|
<Currency>EUR</Currency> |
41
|
|
|
</Currencies> |
42
|
|
|
</Terminal> |
43
|
|
|
<Terminal> |
44
|
|
|
<Title>AltaPay BankPayment Terminal</Title> |
45
|
|
|
<Country></Country> |
46
|
|
|
<Natures> |
47
|
|
|
<Nature>BankPayment</Nature> |
48
|
|
|
</Natures> |
49
|
|
|
<Currencies> |
50
|
|
|
<Currency>EUR</Currency> |
51
|
|
|
</Currencies> |
52
|
|
|
</Terminal> |
53
|
|
|
</Terminals> |
54
|
|
|
</Body> |
55
|
|
|
</APIResponse> |
56
|
|
|
XML; |
57
|
|
|
|
58
|
|
|
$terminal = $this->createMock(Terminal::class); |
59
|
|
|
|
60
|
|
|
$psrResponse = $this->createMock(ResponseInterface::class); |
61
|
|
|
$psrResponse |
62
|
|
|
->expects($this->any()) |
63
|
|
|
->method('getBody') |
64
|
|
|
->willReturn($xml) |
65
|
|
|
; |
66
|
|
|
$getTerminalsResponse = new GetTerminals($psrResponse); |
67
|
|
|
|
68
|
|
|
/** @var TerminalManager|\PHPUnit_Framework_MockObject_MockObject $terminalManager */ |
69
|
|
|
$terminalManager = $this->getMockBuilder(TerminalManager::class) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->setMethods(['create', 'update', 'findTerminalByTitle']) |
72
|
|
|
->getMock() |
73
|
|
|
; |
74
|
|
|
|
75
|
|
|
$terminalManager |
|
|
|
|
76
|
|
|
->expects($this->any()) |
77
|
|
|
->method('create') |
78
|
|
|
->willReturn($terminal) |
79
|
|
|
; |
80
|
|
|
|
81
|
|
|
$terminalManager |
82
|
|
|
->expects($this->any()) |
83
|
|
|
->method('update') |
84
|
|
|
->willReturn(null) |
85
|
|
|
; |
86
|
|
|
|
87
|
|
|
$terminalManager |
88
|
|
|
->expects($this->any()) |
89
|
|
|
->method('findTerminalByTitle') |
90
|
|
|
->willReturn(null) |
91
|
|
|
; |
92
|
|
|
|
93
|
|
|
$altapayClient = $this->createMock(Client::class); |
94
|
|
|
$altapayClient |
95
|
|
|
->expects($this->any()) |
96
|
|
|
->method('getTerminals') |
97
|
|
|
->willReturn($getTerminalsResponse) |
98
|
|
|
; |
99
|
|
|
|
100
|
|
|
$terminalSynchronizer = new TerminalSynchronizer($terminalManager, $altapayClient); |
101
|
|
|
$terminalSynchronizer->syncAll(); |
102
|
|
|
|
103
|
|
|
$this->assertTrue(true); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: