TestCase   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 12 2
A mockApplication() 0 9 1
A setUp() 0 5 1
A tearDown() 0 5 1
1
<?php
2
3
namespace leandrogehlen\querybuilder\tests\unit;
4
5
use yii\base\NotSupportedException;
6
use Yii;
7
8
/**
9
 * This is the base class for all unit tests.
10
 */
11
class TestCase extends  \PHPUnit\Framework\TestCase
12
{
13
    /**
14
     * This method is called before the first test of this test class is run.
15
     * Attempts to load vendor autoloader.
16
     * @throws \yii\base\NotSupportedException
17
     */
18
    public static function setUpBeforeClass()
19
    {
20
        $vendorDir = __DIR__ . '/../vendor';
21
        $vendorAutoload = $vendorDir . '/autoload.php';
22
        if (file_exists($vendorAutoload)) {
23
            require_once($vendorAutoload);
24
        } else {
25
            throw new NotSupportedException("Vendor autoload file '{$vendorAutoload}' is missing.");
26
        }
27
        require_once($vendorDir . '/yiisoft/yii2/Yii.php');
28
        Yii::setAlias('@vendor', $vendorDir);
29
    }
30
31
    /**
32
     * Populates Yii::$app with a new application
33
     */
34
    protected function mockApplication()
35
    {
36
        static $config = [
37
            'id' => 'querybuilder-test',
38
            'basePath' => __DIR__,
39
        ];
40
        $config['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor';
41
        new \yii\console\Application($config);
42
    }
43
44
    /**
45
     * Sets up before test
46
     */
47
    protected function setUp()
48
    {
49
        parent::setUp();
50
        $this->mockApplication();
51
    }
52
53
    /**
54
     * Clean up after test.
55
     * The application created with [[mockApplication]] will be destroyed.
56
     */
57
    protected function tearDown()
58
    {
59
        parent::tearDown();
60
        Yii::$app = null;
61
    }
62
}
63