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([ |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.