1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Tests\Models\Subscriptions; |
4
|
|
|
|
5
|
|
|
use ByTIC\Payments\Models\Subscriptions\Subscriptions; |
6
|
|
|
use ByTIC\Payments\Subscriptions\ChargeMethods\Gateway; |
7
|
|
|
use ByTIC\Payments\Subscriptions\ChargeMethods\Internal; |
8
|
|
|
use ByTIC\Payments\Subscriptions\Statuses\Active; |
9
|
|
|
use ByTIC\Payments\Subscriptions\Statuses\NotStarted; |
10
|
|
|
use ByTIC\Payments\Tests\AbstractTest; |
11
|
|
|
use Mockery\Mock; |
12
|
|
|
use Nip\Database\Query\Select; |
13
|
|
|
use Nip\Records\Collections\Collection; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class SubscriptionsTraitTest |
17
|
|
|
* @package ByTIC\Payments\Tests\Models\Subscriptions |
18
|
|
|
*/ |
19
|
|
|
class SubscriptionsTraitTest extends AbstractTest |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
public function test_getStatuses() |
23
|
|
|
{ |
24
|
|
|
$statuses = Subscriptions::instance()->getStatuses(); |
25
|
|
|
|
26
|
|
|
self::assertCount(4, $statuses); |
27
|
|
|
|
28
|
|
|
self::assertInstanceOf(Active::class, $statuses[Active::NAME]); |
29
|
|
|
self::assertInstanceOf(NotStarted::class, $statuses[NotStarted::NAME]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function test_getChargeMethods() |
33
|
|
|
{ |
34
|
|
|
$repository = Subscriptions::instance(); |
35
|
|
|
|
36
|
|
|
$methods = $repository->getChargeMethods(); |
37
|
|
|
|
38
|
|
|
self::assertCount(2, $methods); |
39
|
|
|
self::assertInstanceOf(Internal::class, $methods['internal']); |
40
|
|
|
self::assertInstanceOf(Gateway::class, $methods['gateway']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function test_findChargeDue() |
44
|
|
|
{ |
45
|
|
|
/** @var Mock|Subscriptions $repository */ |
46
|
|
|
$repository = \Mockery::mock(Subscriptions::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
47
|
|
|
$repository->shouldReceive('findByQuery') |
48
|
|
|
->with(\Mockery::capture($query)) |
49
|
|
|
->andReturn(new Collection()); |
50
|
|
|
|
51
|
|
|
$repository->findChargeDue(10); |
52
|
|
|
|
53
|
|
|
self::assertInstanceOf(Select::class, $query); |
54
|
|
|
self::assertSame( |
55
|
|
|
'SELECT `payments-subscriptions`.* ' |
56
|
|
|
. 'FROM `payments-subscriptions` ' |
57
|
|
|
. 'WHERE charge_at IS NOT NULL AND charge_at < NOW() ' |
58
|
|
|
. 'ORDER BY `charge_at` ASC LIMIT 10', |
59
|
|
|
(string)$query |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |