Completed
Push — master ( 57b029...64d1a0 )
by Igor
03:37
created

TestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 6
rs 9.4285
c 2
b 0
f 1
cc 1
eloc 3
nc 1
nop 0
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