ModuleTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 72
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 23 1
A tearDown() 0 3 1
A testGetCollection() 0 4 1
A testGetMerchant() 0 7 1
A testGetWorker() 0 6 1
1
<?php
2
/**
3
 * Yii2 extension for payment processing with Omnipay, Payum and more later.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-merchant
6
 * @package   yii2-merchant
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\merchant\tests\unit;
12
13
use hiqdev\php\merchant\OmnipayMerchant;
14
use hiqdev\yii2\merchant\Collection;
15
use hiqdev\yii2\merchant\Module;
16
use Yii;
17
use yii\web\Application;
18
19
/**
20
 * Module test suite.
21
 */
22
class ModuleTest extends \PHPUnit\Framework\TestCase
23
{
24
    /**
25
     * @var Module
26
     */
27
    protected $module;
28
29
    protected $gateways = [
30
        'Stripe' => [
31
            'purse'     => 'asd',
32
            'secret'    => '123',
33
        ],
34
        'wmusd' => [
35
            'gateway'   => 'WebMoney',
36
            'purse'     => 'Z0000000',
37
            'secret'    => '123',
38
        ],
39
        'fake' => [
40
            'class'     => 'hiqdev\yii2\merchant\tests\unit\FakeMerchant',
41
            'purse'     => 'SDF',
42
            'secret'    => '000',
43
        ],
44
    ];
45
46
    protected function setUp()
47
    {
48
        $application = new Application([
0 ignored issues
show
Unused Code introduced by
$application is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
            'id'       => 'fake',
50
            'basePath' => dirname(dirname(__DIR__)),
51
            'modules'  => [
52
                'merchant' => [
53
                    'class'      => Module::class,
54
                    'username'   => 'fake',
55
                    'notifyPage' => '/my/notify/page',
56
                    'returnPage' => '/merchant/pay/return',
57
                    'cancelPage' => '/merchant/pay/cancel',
58
                    'collection' => $this->gateways,
59
                ],
60
            ],
61
            'container' => [
62
                'singletons' => [
63
                    \hiqdev\yii2\merchant\transactions\TransactionRepositoryInterface::class => \hiqdev\yii2\merchant\tests\unit\FakeTransactionRepository::class,
64
                ],
65
            ],
66
        ]);
67
        $this->module = Yii::$app->getModule('merchant');
68
    }
69
70
    protected function tearDown()
71
    {
72
    }
73
74
    public function testGetCollection()
75
    {
76
        $this->assertInstanceOf(Collection::class, $this->module->collection);
77
    }
78
79
    public function testGetMerchant()
80
    {
81
        $this->assertInstanceOf(FakeMerchant::class, $this->module->collection->fake);
82
        $this->assertInstanceOf(OmnipayMerchant::class, $this->module->collection->wmusd);
83
        $this->assertSame($this->gateways['wmusd']['purse'], $this->module->collection->wmusd->data['purse']);
84
        $this->assertSame($this->gateways['fake']['secret'], $this->module->collection->fake->data['secret']);
85
    }
86
87
    public function testGetWorker()
88
    {
89
        $this->assertInstanceOf(FakeGateway::class, $this->module->collection->fake->getWorker());
90
        $this->assertInstanceOf('Omnipay\Stripe\Gateway', $this->module->collection->Stripe->getWorker());
91
        $this->assertInstanceOf('Omnipay\WebMoney\Gateway', $this->module->collection->wmusd->getWorker());
92
    }
93
}
94