Completed
Push — master ( e48e3f...5ab19a )
by Vuong
01:30
created

TestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A tearDown() 0 6 1
A mockApplication() 0 17 1
A destroyApplication() 0 7 1
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-async
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\async;
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\web\Application'): void
47
    {
48
        new $appClass(ArrayHelper::merge([
49
            'id' => 'test',
50
            'basePath' => __DIR__,
51
            'vendorPath' => dirname(__DIR__) . '/vendor',
52
            'components' => [
53
                'request' => [
54
                    'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
55
                    'scriptFile' => __DIR__ . '/index.php',
56
                    'scriptUrl' => '/index.php',
57
                    'url' => 'http://abc.test'
58
                ],
59
                'async' => 'vxm\async\Async'
60
            ]
61
        ], $config));
62
    }
63
64
    /**
65
     * Destroys application in Yii::$app by setting it to null.
66
     */
67
    protected function destroyApplication(): void
68
    {
69
        $_SERVER['HTTP_USER_AGENT'] = null;
70
        $_SERVER['REQUEST_METHOD'] = 'GET';
71
72
        Yii::$app = null;
73
    }
74
75
76
}
77