Passed
Push — master ( 19a915...d9efc8 )
by Gabriel
14:56
created

SubscriptionsTraitTest::test_getChargeMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 9
rs 10
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
}