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\Statuses\Active; |
12
|
|
|
use ByTIC\Payments\Subscriptions\Statuses\NotStarted; |
13
|
|
|
use ByTIC\Payments\Tests\AbstractTest; |
14
|
|
|
use Nip\Database\Query\Insert; |
15
|
|
|
use Nip\Records\AbstractModels\Record; |
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
|
|
|
public function test_getStatuses() |
26
|
|
|
{ |
27
|
|
|
$statuses = Subscriptions::instance()->getStatuses(); |
28
|
|
|
|
29
|
|
|
self::assertCount(4, $statuses); |
30
|
|
|
|
31
|
|
|
self::assertInstanceOf(Active::class, $statuses[Active::NAME]); |
32
|
|
|
self::assertInstanceOf(NotStarted::class, $statuses[NotStarted::NAME]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function test_populateFromToken() |
36
|
|
|
{ |
37
|
|
|
ModelLocator::set(Tokens::class, Tokens::instance()); |
38
|
|
|
|
39
|
|
|
$repository = \Mockery::mock(Subscriptions::class)->shouldAllowMockingProtectedMethods()->makePartial(); |
40
|
|
|
$repository->shouldReceive('initRelationsTransactions'); |
41
|
|
|
$repository->shouldReceive('initRelationsLastTransaction'); |
42
|
|
|
$repository->setPrimaryKey('id'); |
43
|
|
|
|
44
|
|
|
$item = new Subscription(); |
45
|
|
|
$item->setManager($repository); |
46
|
|
|
|
47
|
|
|
$token = new Token(); |
48
|
|
|
$token->id = 7; |
49
|
|
|
$item->populateFromToken($token); |
50
|
|
|
|
51
|
|
|
self::assertSame(7, $item->getPropertyRaw('id_token')); |
52
|
|
|
self::assertSame($token, $item->getToken()); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function test_cast_metadata() |
56
|
|
|
{ |
57
|
|
|
$item = new Subscription(); |
58
|
|
|
|
59
|
|
|
$metadata = $item->metadata; |
|
|
|
|
60
|
|
|
self::assertInstanceOf(\ByTIC\DataObjects\Casts\Metadata\Metadata::class, $metadata); |
61
|
|
|
|
62
|
|
|
$item->addMedata('test', 99); |
63
|
|
|
self::assertSame(99, $item->metadata['test']); |
64
|
|
|
|
65
|
|
|
self::assertSame('{"test":99}', $item->getPropertyRaw('metadata')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function test_cast_metadata_empty() |
69
|
|
|
{ |
70
|
|
|
$repository = \Mockery::mock(Transactions::class)->shouldAllowMockingProtectedMethods()->makePartial(); |
71
|
|
|
$repository->shouldReceive('insertQuery')->once()->andReturn(new Insert()); |
72
|
|
|
$repository->shouldReceive('performInsert')->once(); |
73
|
|
|
$repository->bootTransactionsTrait(); |
74
|
|
|
|
75
|
|
|
$item = new Transaction(); |
76
|
|
|
$item->setManager($repository); |
77
|
|
|
$item->insert(); |
78
|
|
|
|
79
|
|
|
self::assertSame('{}', $item->getPropertyRaw('metadata')); |
80
|
|
|
} |
81
|
|
|
} |