|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PROCERGS\LoginCidadao\AccountingBundle\Tests\Model; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use PROCERGS\LoginCidadao\AccountingBundle\Entity\ProcergsLink; |
|
15
|
|
|
use PROCERGS\LoginCidadao\AccountingBundle\Model\AccountingReportEntry; |
|
16
|
|
|
use PROCERGS\LoginCidadao\AccountingBundle\Model\GcsInterface; |
|
17
|
|
|
|
|
18
|
|
|
class GcsInterfaceTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testGcsInterface() |
|
21
|
|
|
{ |
|
22
|
|
|
$today = (new \DateTime())->format('dmY'); |
|
23
|
|
|
$interfaceName = 'MY_INTERFACE'; |
|
24
|
|
|
$start = \DateTime::createFromFormat('Y-m-d', '2017-01-01'); |
|
25
|
|
|
$config = []; |
|
26
|
|
|
|
|
27
|
|
|
$clients = [ |
|
28
|
|
|
(new AccountingReportEntry()) |
|
29
|
|
|
->setSystemType(ProcergsLink::TYPE_INTERNAL) |
|
30
|
|
|
->setProcergsInitials(['XPTO']) |
|
31
|
|
|
->setAccessTokens(111) |
|
32
|
|
|
->setApiUsage(111) |
|
33
|
|
|
->setProcergsOwner(['SOME_OWNER']), |
|
34
|
|
|
(new AccountingReportEntry()) |
|
35
|
|
|
->setSystemType(ProcergsLink::TYPE_INTERNAL) |
|
36
|
|
|
->setProcergsInitials(['XPTO']) |
|
37
|
|
|
->setAccessTokens(222) |
|
38
|
|
|
->setApiUsage(222) |
|
39
|
|
|
->setProcergsOwner(['SOME_OWNER']), |
|
40
|
|
|
(new AccountingReportEntry()) |
|
41
|
|
|
->setSystemType(ProcergsLink::TYPE_EXTERNAL) |
|
42
|
|
|
->setAccessTokens(333) |
|
43
|
|
|
->setApiUsage(333), |
|
44
|
|
|
(new AccountingReportEntry()) |
|
45
|
|
|
->setSystemType(ProcergsLink::TYPE_INTERNAL) |
|
46
|
|
|
->setAccessTokens(444) |
|
47
|
|
|
->setApiUsage(444), |
|
48
|
|
|
(new AccountingReportEntry()) |
|
49
|
|
|
->setSystemType('invalid') |
|
50
|
|
|
->setAccessTokens(444) |
|
51
|
|
|
->setApiUsage(444), |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
$expectedBody = implode(PHP_EOL, [ |
|
55
|
|
|
'2;SOME_OWNER;XPTO;'.(111 + 111 + 222 + 222), |
|
56
|
|
|
'2;EXTERNAL;EXTERNAL;'.(333 + 333), |
|
57
|
|
|
'2;;;'.(444 + 444), |
|
58
|
|
|
'2;;;'.(444 + 444), |
|
59
|
|
|
]); |
|
60
|
|
|
|
|
61
|
|
|
$gcsInterface = new GcsInterface($interfaceName, $start, $config); |
|
62
|
|
|
foreach ($clients as $client) { |
|
63
|
|
|
$gcsInterface->addClient($client); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$header = "1;{$interfaceName};012017;{$today}"; |
|
67
|
|
|
$tail = "9;4"; |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals($header, $gcsInterface->getHeader()); |
|
70
|
|
|
$this->assertEquals($expectedBody, $gcsInterface->getBody()); |
|
71
|
|
|
$this->assertEquals($tail, $gcsInterface->getTail()); |
|
72
|
|
|
$this->assertEquals($header.PHP_EOL.$expectedBody.PHP_EOL.$tail, $gcsInterface->__toString()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testConfig() |
|
76
|
|
|
{ |
|
77
|
|
|
$today = (new \DateTime())->format('dmY'); |
|
78
|
|
|
$interfaceName = 'MY_INTERFACE'; |
|
79
|
|
|
$start = \DateTime::createFromFormat('Y-m-d', '2017-01-01'); |
|
80
|
|
|
$config = [ |
|
81
|
|
|
'ignore_externals' => true, |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
$clients = [ |
|
85
|
|
|
(new AccountingReportEntry()) |
|
86
|
|
|
->setSystemType(ProcergsLink::TYPE_EXTERNAL) |
|
87
|
|
|
->setAccessTokens(333) |
|
88
|
|
|
->setApiUsage(333), |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
|
|
$gcsInterface = new GcsInterface($interfaceName, $start, $config); |
|
92
|
|
|
foreach ($clients as $client) { |
|
93
|
|
|
$gcsInterface->addClient($client); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$header = "1;{$interfaceName};012017;{$today}"; |
|
97
|
|
|
$body = ''; |
|
98
|
|
|
$tail = "9;0"; |
|
99
|
|
|
|
|
100
|
|
|
$this->assertEquals($header, $gcsInterface->getHeader()); |
|
101
|
|
|
$this->assertEquals($body, $gcsInterface->getBody()); |
|
102
|
|
|
$this->assertEquals($tail, $gcsInterface->getTail()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|