1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii2VN |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace vxm\test\unit\mfa; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
use yii\helpers\ArrayHelper; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class TestCase |
18
|
|
|
* |
19
|
|
|
* @author Vuong Minh <[email protected]> |
20
|
|
|
* @since 1.0 |
21
|
|
|
*/ |
22
|
|
|
class TestCase extends BaseTestCase |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$this->mockApplication(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function tearDown(): void |
34
|
|
|
{ |
35
|
|
|
parent::tearDown(); |
36
|
|
|
|
37
|
|
|
$this->destroyApplication(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Populates Yii::$app with a new application |
42
|
|
|
* The application will be destroyed on tearDown() automatically. |
43
|
|
|
* @param array $config The application configuration, if needed |
44
|
|
|
* @param string $appClass name of the application class to create |
45
|
|
|
*/ |
46
|
|
|
protected function mockApplication($config = [], $appClass = '\yii\web\Application') |
47
|
|
|
{ |
48
|
|
|
new $appClass(ArrayHelper::merge([ |
49
|
|
|
'id' => 'test', |
50
|
|
|
'basePath' => __DIR__, |
51
|
|
|
'vendorPath' => dirname(__DIR__, 2) . '/vendor', |
52
|
|
|
'components' => [ |
53
|
|
|
'user' => [ |
54
|
|
|
'identityClass' => Identity::class, |
55
|
|
|
'as mfa' => [ |
56
|
|
|
'class' => 'vxm\mfa\Behavior', |
57
|
|
|
'verifyUrl' => 'site/verify' |
58
|
|
|
] |
59
|
|
|
], |
60
|
|
|
'request' => [ |
61
|
|
|
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', |
62
|
|
|
'scriptFile' => __DIR__ . '/index.php', |
63
|
|
|
'scriptUrl' => '/index.php', |
64
|
|
|
'url' => 'http://abc.test' |
65
|
|
|
] |
66
|
|
|
], |
67
|
|
|
], $config)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Destroys application in Yii::$app by setting it to null. |
72
|
|
|
*/ |
73
|
|
|
protected function destroyApplication() |
74
|
|
|
{ |
75
|
|
|
if (Yii::$app && Yii::$app->has('session', true)) { |
76
|
|
|
Yii::$app->session->destroy(); |
77
|
|
|
Yii::$app->session->close(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
Yii::$app = null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|