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\jsParams; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
use yii\base\Event; |
13
|
|
|
use yii\helpers\ArrayHelper; |
14
|
|
|
use yii\web\View; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class TestCase |
20
|
|
|
* |
21
|
|
|
* @author Vuong Minh <[email protected]> |
22
|
|
|
* @since 1.0 |
23
|
|
|
*/ |
24
|
|
|
class TestCase extends BaseTestCase |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
public function setUp(): void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->mockApplication(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function tearDown(): void |
36
|
|
|
{ |
37
|
|
|
parent::tearDown(); |
38
|
|
|
|
39
|
|
|
$this->destroyApplication(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Populates Yii::$app with a new application |
44
|
|
|
* The application will be destroyed on tearDown() automatically. |
45
|
|
|
* @param array $config The application configuration, if needed |
46
|
|
|
* @param string $appClass name of the application class to create |
47
|
|
|
*/ |
48
|
|
|
protected function mockApplication($config = [], $appClass = '\yii\web\Application'): void |
49
|
|
|
{ |
50
|
|
|
new $appClass(ArrayHelper::merge([ |
51
|
|
|
'id' => 'test', |
52
|
|
|
'basePath' => __DIR__, |
53
|
|
|
'bootstrap' => ['vxm\jsParams\ViewRenderer'], |
54
|
|
|
'vendorPath' => dirname(__DIR__) . '/vendor', |
55
|
|
|
'components' => [ |
56
|
|
|
'view' => [ |
57
|
|
|
'renderers' => [ |
58
|
|
|
'tpl' => 'yii\smarty\ViewRenderer', |
59
|
|
|
'twig' => 'yii\twig\ViewRenderer' |
60
|
|
|
], |
61
|
|
|
], |
62
|
|
|
'request' => [ |
63
|
|
|
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', |
64
|
|
|
'scriptFile' => __DIR__ . '/index.php', |
65
|
|
|
'scriptUrl' => '/index.php', |
66
|
|
|
'url' => 'http://abc.test' |
67
|
|
|
] |
68
|
|
|
], |
69
|
|
|
], $config)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Destroys application in Yii::$app by setting it to null. |
74
|
|
|
*/ |
75
|
|
|
protected function destroyApplication(): void |
76
|
|
|
{ |
77
|
|
|
Yii::$app = null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|