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