1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Tests\Models\Subscriptions; |
4
|
|
|
|
5
|
|
|
use ByTIC\Payments\Models\Methods\PaymentMethods; |
6
|
|
|
use ByTIC\Payments\Models\Subscriptions\Subscription; |
7
|
|
|
use ByTIC\Payments\Models\Subscriptions\Subscriptions; |
8
|
|
|
use ByTIC\Payments\Models\Tokens\Token; |
9
|
|
|
use ByTIC\Payments\Models\Tokens\Tokens; |
10
|
|
|
use ByTIC\Payments\Models\Transactions\Transaction; |
11
|
|
|
use ByTIC\Payments\Models\Transactions\Transactions; |
12
|
|
|
use ByTIC\Payments\Subscriptions\ChargeMethods\Gateway; |
13
|
|
|
use ByTIC\Payments\Subscriptions\ChargeMethods\Internal; |
14
|
|
|
use Paytic\Payments\Tests\AbstractTest; |
15
|
|
|
use Nip\Database\Query\Insert; |
16
|
|
|
use Nip\Records\Locator\ModelLocator; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class SubscriptionTraitTest |
20
|
|
|
* @package ByTIC\Payments\Tests\Models\Subscriptions |
21
|
|
|
*/ |
22
|
|
|
class SubscriptionTraitTest extends AbstractTest |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @dataProvider data_getChargeMethod |
27
|
|
|
*/ |
28
|
|
|
public function test_getChargeMethod($value, $class) |
29
|
|
|
{ |
30
|
|
|
$repository = new Subscriptions(); |
31
|
|
|
|
32
|
|
|
$item = new Subscription(); |
33
|
|
|
$item->fill(['charge_method' => $value]); |
34
|
|
|
$item->setManager($repository); |
35
|
|
|
|
36
|
|
|
self::assertInstanceOf($class, $item->getChargeMethod()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function data_getChargeMethod(): array |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
['', Internal::class], |
43
|
|
|
[Internal::NAME, Internal::class], |
44
|
|
|
[Gateway::NAME, Gateway::class], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function test_populateFromToken() |
49
|
|
|
{ |
50
|
|
|
ModelLocator::set(Tokens::class, new Tokens()); |
51
|
|
|
ModelLocator::set(PaymentMethods::class, new PaymentMethods()); |
52
|
|
|
|
53
|
|
|
$repository = \Mockery::mock(Subscriptions::class)->shouldAllowMockingProtectedMethods()->makePartial(); |
54
|
|
|
$repository->shouldReceive('initRelationsTransactions'); |
55
|
|
|
$repository->shouldReceive('initRelationsLastTransaction'); |
56
|
|
|
$repository->setPrimaryKey('id'); |
57
|
|
|
|
58
|
|
|
$item = new Subscription(); |
59
|
|
|
$item->setManager($repository); |
60
|
|
|
|
61
|
|
|
$token = new Token(); |
62
|
|
|
$token->id = 7; |
63
|
|
|
$item->populateFromToken($token); |
64
|
|
|
|
65
|
|
|
self::assertSame(7, $item->getPropertyRaw('id_token')); |
66
|
|
|
self::assertSame($token, $item->getToken()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function test_cast_metadata() |
70
|
|
|
{ |
71
|
|
|
$item = new Subscription(); |
72
|
|
|
|
73
|
|
|
$metadata = $item->metadata; |
|
|
|
|
74
|
|
|
self::assertInstanceOf(\ByTIC\DataObjects\Casts\Metadata\Metadata::class, $metadata); |
75
|
|
|
|
76
|
|
|
$item->addMedata('test', 99); |
77
|
|
|
self::assertSame(99, $item->metadata['test']); |
78
|
|
|
|
79
|
|
|
self::assertSame('{"test":99}', $item->getPropertyRaw('metadata')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function test_cast_metadata_empty() |
83
|
|
|
{ |
84
|
|
|
$repository = \Mockery::mock(Transactions::class)->shouldAllowMockingProtectedMethods()->makePartial(); |
85
|
|
|
$repository->shouldReceive('insertQuery')->once()->andReturn(new Insert()); |
86
|
|
|
$repository->shouldReceive('performInsert')->once(); |
87
|
|
|
$repository->bootTransactionsTrait(); |
88
|
|
|
|
89
|
|
|
$item = new Transaction(); |
90
|
|
|
$item->setManager($repository); |
91
|
|
|
$item->insert(); |
92
|
|
|
|
93
|
|
|
self::assertSame('{}', $item->getPropertyRaw('metadata')); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|