|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Action; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Action\DatatransAction; |
|
8
|
|
|
use ApplicationTest\Traits\TestWithTransaction; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
11
|
|
|
use Zend\Diactoros\ServerRequest; |
|
12
|
|
|
use Zend\Expressive\Template\TemplateRendererInterface; |
|
13
|
|
|
|
|
14
|
|
|
class DatatransActionTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
use TestWithTransaction; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @dataProvider providerProcess |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testProcess(array $data, string $expectedAmount, array $expectedViewModel): void |
|
22
|
|
|
{ |
|
23
|
|
|
// Message always include input data |
|
24
|
|
|
$expectedViewModel['message']['detail'] = $data; |
|
25
|
|
|
$renderer = $this->prophesize(TemplateRendererInterface::class); //; $container->get(TemplateRendererInterface::class); |
|
26
|
|
|
$renderer->render('app::datatrans', $expectedViewModel); |
|
27
|
|
|
|
|
28
|
|
|
$handler = $this->prophesize(RequestHandlerInterface::class); |
|
29
|
|
|
|
|
30
|
|
|
$request = new ServerRequest(); |
|
31
|
|
|
$request = $request->withParsedBody($data); |
|
32
|
|
|
|
|
33
|
|
|
$action = new DatatransAction(_em(), $renderer->reveal()); |
|
34
|
|
|
$action->process($request, $handler->reveal()); |
|
35
|
|
|
|
|
36
|
|
|
$actualBalance = _em()->getConnection()->fetchColumn('SELECT balance FROM account WHERE owner_id = 1007'); |
|
37
|
|
|
self::assertSame($expectedAmount, $actualBalance); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function providerProcess(): array |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
[ |
|
44
|
|
|
[ |
|
45
|
|
|
'uppTransactionId' => '123456789012345678', |
|
46
|
|
|
'status' => 'success', |
|
47
|
|
|
'refno' => '1007', |
|
48
|
|
|
'amount' => '10000', |
|
49
|
|
|
'currency' => 'CHF', |
|
50
|
|
|
'responseMessage' => 'Payment was successful', |
|
51
|
|
|
], |
|
52
|
|
|
'100.00', |
|
53
|
|
|
[ |
|
54
|
|
|
'message' => [ |
|
55
|
|
|
'type' => 'success', |
|
56
|
|
|
'message' => 'Payment was successful', |
|
57
|
|
|
], |
|
58
|
|
|
], |
|
59
|
|
|
], |
|
60
|
|
|
[ |
|
61
|
|
|
[ |
|
62
|
|
|
'uppTransactionId' => '876543210987654321', |
|
63
|
|
|
'status' => 'error', |
|
64
|
|
|
'errorMessage' => 'Dear Sir/Madam, Fire! fire! help me! All the best, Maurice Moss.', |
|
65
|
|
|
], |
|
66
|
|
|
'0.00', |
|
67
|
|
|
[ |
|
68
|
|
|
'message' => [ |
|
69
|
|
|
'type' => 'error', |
|
70
|
|
|
'message' => 'Dear Sir/Madam, Fire! fire! help me! All the best, Maurice Moss.', |
|
71
|
|
|
], |
|
72
|
|
|
], |
|
73
|
|
|
], |
|
74
|
|
|
[ |
|
75
|
|
|
[ |
|
76
|
|
|
'uppTransactionId' => '876543210987654321', |
|
77
|
|
|
'status' => 'cancel', |
|
78
|
|
|
], |
|
79
|
|
|
'0.00', |
|
80
|
|
|
[ |
|
81
|
|
|
'message' => [ |
|
82
|
|
|
'type' => 'error', |
|
83
|
|
|
'message' => 'Cancelled', |
|
84
|
|
|
], |
|
85
|
|
|
], |
|
86
|
|
|
], |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|