GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BaseTestCase   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 5 1
A getParam() 0 8 3
A mockApplication() 0 8 1
A mockWebApplication() 0 15 1
A getVendorPath() 0 8 2
A destroyApplication() 0 7 3
A assertEqualsWithoutLE() 0 7 1
1
<?php
2
3
namespace miloschumanunit\highcharts;
4
5
use yii\helpers\ArrayHelper;
6
7
/**
8
 * This is the base class for all yii framework unit tests.
9
 */
10
abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
11
{
12
    public static $params;
13
14
    /**
15
     * Clean up after test.
16
     * By default the application created with [[mockApplication]] will be destroyed.
17
     */
18
    protected function tearDown()
19
    {
20
        parent::tearDown();
21
        $this->destroyApplication();
22
    }
23
24
    /**
25
     * Returns a test configuration param from /data/config.php
26
     * @param  string $name params name
27
     * @param  mixed $default default value to use when param is not set.
28
     * @return mixed  the value of the configuration param
29
     */
30
    public static function getParam($name, $default = null)
31
    {
32
        if (static::$params === null) {
33
            static::$params = require(__DIR__ . '/data/config.php');
34
        }
35
36
        return isset(static::$params[$name]) ? static::$params[$name] : $default;
37
    }
38
39
    /**
40
     * Populates Yii::$app with a new application
41
     * The application will be destroyed on tearDown() automatically.
42
     * @param array $config The application configuration, if needed
43
     * @param string $appClass name of the application class to create
44
     */
45
    protected function mockApplication($config = [], $appClass = '\yii\console\Application')
46
    {
47
        new $appClass(ArrayHelper::merge([
48
            'id' => 'testapp',
49
            'basePath' => __DIR__,
50
            'vendorPath' => $this->getVendorPath(),
51
        ], $config));
52
    }
53
54
    protected function mockWebApplication($config = [], $appClass = '\yii\web\Application')
55
    {
56
        new $appClass(ArrayHelper::merge([
57
            'id' => 'testapp',
58
            'basePath' => __DIR__,
59
            'vendorPath' => $this->getVendorPath(),
60
            'components' => [
61
                'request' => [
62
                    'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
63
                    'scriptFile' => __DIR__ .'/index.php',
64
                    'scriptUrl' => '/index.php',
65
                ],
66
            ]
67
        ], $config));
68
    }
69
70
    protected function getVendorPath()
71
    {
72
        $vendor = dirname(dirname(__DIR__)) . '/vendor';
73
        if (!is_dir($vendor)) {
74
            $vendor = dirname(dirname(dirname(dirname(__DIR__))));
75
        }
76
        return $vendor;
77
    }
78
79
    /**
80
     * Destroys application in Yii::$app by setting it to null.
81
     */
82
    protected function destroyApplication()
83
    {
84
        if (\Yii::$app && \Yii::$app->has('session', true)) {
85
            \Yii::$app->session->close();
86
        }
87
        \Yii::$app = null;
88
    }
89
90
    /**
91
     * Asserting two strings equality ignoring line endings
92
     *
93
     * @param string $expected
94
     * @param string $actual
95
     */
96
    public function assertEqualsWithoutLE($expected, $actual)
97
    {
98
        $expected = str_replace("\r\n", "\n", $expected);
99
        $actual = str_replace("\r\n", "\n", $actual);
100
101
        $this->assertEquals($expected, $actual);
102
    }
103
}
104