TestCase::mockApplication()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 yiiviet\tests\unit\validator;
9
10
use Yii;
11
12
use yii\helpers\ArrayHelper;
13
use yiiviet\validator\Bootstrap;
14
15
use PHPUnit\Framework\TestCase as BaseTestCase;
16
17
/**
18
 * Class TestCase
19
 *
20
 * @author Vuong Minh <[email protected]>
21
 * @since 1.0
22
 */
23
class TestCase extends BaseTestCase
24
{
25
26
27
    public function setUp()
28
    {
29
        $this->mockApplication();
30
31
        parent::setUp();
32
    }
33
34
    public function tearDown()
35
    {
36
        $this->destroyApplication();
37
38
        parent::tearDown();
39
    }
40
41
    protected function mockApplication($config = [], $appClass = '\yii\console\Application')
42
    {
43
        new $appClass(ArrayHelper::merge([
44
            'id' => 'testapp',
45
            'basePath' => __DIR__,
46
            'bootstrap' => [
47
                Bootstrap::class
48
            ],
49
            'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
50
        ], $config));
51
    }
52
53
    /**
54
     * Destroys application in Yii::$app by setting it to null.
55
     */
56
    protected function destroyApplication()
57
    {
58
        Yii::$app = null;
59
    }
60
61
62
}
63