TestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 7 1
A mockApplication() 0 15 1
A destroyApplication() 0 4 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 Symfony\Component\Stopwatch\Stopwatch;
13
14
use PHPUnit\Framework\TestCase as BaseTestCase;
15
16
use yii\helpers\ArrayHelper;
17
18
/**
19
 * Class TestCase
20
 *
21
 * @author Vuong Minh <[email protected]>
22
 * @since 1.0
23
 */
24
class TestCase extends BaseTestCase
25
{
26
    /**
27
     * @var Stopwatch
28
     */
29
    protected $stopwatch;
30
31
    public function setUp(): void
32
    {
33
        parent::setUp();
34
35
        $this->mockApplication();
36
        $this->stopwatch = new Stopwatch;
37
    }
38
39
    public function tearDown(): void
40
    {
41
        parent::tearDown();
42
43
        $this->destroyApplication();
44
        $this->stopwatch = null;
45
    }
46
47
    /**
48
     * Populates Yii::$app with a new application
49
     * The application will be destroyed on tearDown() automatically.
50
     * @param array $config The application configuration, if needed
51
     * @param string $appClass name of the application class to create
52
     */
53
    protected function mockApplication($config = [], $appClass = '\yii\console\Application'): void
54
    {
55
        new $appClass(ArrayHelper::merge([
56
            'id' => 'test',
57
            'basePath' => __DIR__,
58
            'vendorPath' => dirname(__DIR__) . '/vendor',
59
            'components' => [
60
                'async' => [
61
                    'class' => 'vxm\async\Async',
62
                    'timeout' => 5,
63
                    'appConfigFile' => __DIR__ . '/child-app-config.php'
64
                ]
65
            ]
66
        ], $config));
67
    }
68
69
    /**
70
     * Destroys application in Yii::$app by setting it to null.
71
     */
72
    protected function destroyApplication(): void
73
    {
74
        Yii::$app = null;
75
    }
76
77
78
}
79