TestCase   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 57
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A tearDown() 0 4 1
A mockApplication() 0 19 1
A getVendorPath() 0 4 1
A destroyApplication() 0 4 1
1
<?php
2
3
namespace yii2mod\enum\tests;
4
5
use Yii;
6
use yii\helpers\ArrayHelper;
7
8
/**
9
 * This is the base class for all yii framework unit tests.
10
 */
11
class TestCase extends \PHPUnit\Framework\TestCase
12
{
13
    protected function setUp()
14
    {
15
        parent::setUp();
16
17
        $this->mockApplication();
18
    }
19
20
    protected function tearDown()
21
    {
22
        $this->destroyApplication();
23
    }
24
25
    /**
26
     * Populates Yii::$app with a new application
27
     * The application will be destroyed on tearDown() automatically.
28
     *
29
     * @param array $config The application configuration, if needed
30
     * @param string $appClass name of the application class to create
31
     */
32
    protected function mockApplication($config = [], $appClass = '\yii\console\Application')
33
    {
34
        new $appClass(ArrayHelper::merge([
35
            'id' => 'testapp',
36
            'basePath' => __DIR__,
37
            'vendorPath' => $this->getVendorPath(),
38
            'components' => [
39
                'i18n' => [
40
                    'translations' => [
41
                        '*' => [
42
                            'class' => 'yii\i18n\PhpMessageSource',
43
                            'basePath' => '@app/messages', // if advanced application, set @frontend/messages
44
                            'sourceLanguage' => 'en',
45
                        ],
46
                    ],
47
                ],
48
            ],
49
        ], $config));
50
    }
51
52
    /**
53
     * @return string vendor path
54
     */
55
    protected function getVendorPath()
56
    {
57
        return dirname(__DIR__) . '/vendor';
58
    }
59
60
    /**
61
     * Destroys application in Yii::$app by setting it to null.
62
     */
63
    protected function destroyApplication()
64
    {
65
        Yii::$app = null;
66
    }
67
}
68