TestCase   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A tearDown() 0 6 1
A mockApplication() 0 9 1
A destroyApplication() 0 4 1
A mockController() 0 4 1
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\consoleMenu;
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\console\Application')
47
    {
48
        new $appClass(ArrayHelper::merge([
49
            'id' => 'test',
50
            'basePath' => __DIR__,
51
            'bootstrap' => ['vxm\consoleMenu\Bootstrap'],
52
            'vendorPath' => dirname(__DIR__, 2) . '/vendor'
53
        ], $config));
54
    }
55
56
    /**
57
     * Destroys application in Yii::$app by setting it to null.
58
     */
59
    protected function destroyApplication()
60
    {
61
        Yii::$app = null;
62
    }
63
64
    /**
65
     * @param array $config
66
     * @param string $controllerClass
67
     * @return \yii\console\Controller
68
     */
69
    protected function mockController($config = [], $controllerClass = '\vxm\test\unit\consoleMenu\TestController')
70
    {
71
        return new $controllerClass('test', Yii::$app, $config);
72
    }
73
}
74